How to make field readonly in web service
Question:
I have a bug in web service where we need to make a parameter read. There is a code in validateWrite(..) method of the table that adds an AIFFault::checkFailedLogFault if the field is being changed.However, when testing this using the web service in the visual studio solution no error is being raised and the web service is being allowed to change parameter even though when I step into debug the AIFFault::checkFailedLogFault is being called.
Answer:
There are four ways to achieve this through x++ code. There is nothing that web service can do to make visual studio or any other client stopped editing, because web services are asynchronous in nature and web services are not called on the assignment of the value in any client ( I believe user is associating project to the lines from the client and not the code behind web service is doing that). It will raise error when the client submit the code and will fail the creation of the record in case of any error.
1) Write the code on the validate write of the table and return false from there with the checkFailed error message.
2) Delete the field from the query so that user can’t see that field.
3) Manipulate through code in the prepareForSaveEntended method of the Axd class and check if there is a project, blank the field or ignore the user value and use the table value.
4) Use the removeFieldAsTouched() method
How to add reference group control through code
#Define.controlName(TestControl)
FormReferenceGroupControl testReferenceControl = Grid.addControl(FormControlType::ReferenceGroup, #controlName);
testReferenceControl.dataSource(tableStr(testDataSourceTable));
testReferenceControl.referenceField(fieldNum(testDataSourceTable, testField));
testReferenceControl.visible(false);
How to set Fact box properties through code
Hi –
Below is the example that shows how to set properties of the parts through code
int partListCounter;
PartList formPartList;
ListEnumerator partListIterator;
FormRun formPart;
List partList = new List(Types::Class);
for (partListCounter = 1; partListCounter <= formPartList.partCount() ; partListCounter++)
{
formPartList.getPartById(1).dataSource().research();
}
How to check the number of marked records on the Forms
Scenario 1:
User is checking the rows in the grid to mark them for deletion, I want to get the number of checked records to do some thing
Solution
Use the buffer_Ds.recordsMarked().lastIndex() to check the number of the records that are marked for deletion.
Scenario 2:
User has marked the multiple records for deletion on the Form, now I want to do some manipulation on the deletion and refresh the Grid or the Form. What should I do
Solution:
Never write the research code in the delete method because the delete method on the Form is called per row and calling research would break this behavior, since research calls the executeQuery(). DeleteMarked() is the good place to write the research code since it is called once if there are multiple records, you should write the research code just after the super() call.
Note: The deleteMarked() method is not called when there is a single record for the deletion.
How to develop inbound web service in ax 2012
Hi-
This article is about creating inbound web service. Let’s go through step by step to understand the development of it.
First we will discuss the concepts then we will go deeper in the implementation.
Overall picture
How the component are interacting with each other
Steps to develop a web service
1. Create a query
a. Remember to prefix it with Axd
b. Add the fields in this query that you want to expose to the user
c. Right click the fields property and set it to “No”.
d. Remember to delete ‘_1′ suffix from the data source’s name
2. Go to tools –> Wizard –> Aif Document wizard
3. For the inbound service, you need to check the “create” check box, since the inbound service will be creating the record. For generating AxBc class, just click the Generate Axbc check.
4. On finishing this wizard, you would have the project with the axbc and Axd classes.
5. Remove the cache method from the axbc class to remove the error
6. Your web service is ready
7. Right click the service and click addins –> register service.
8. Create a inbound port to expose this service
Some important method
Where to write code for the validations and saving?
Axd**** class –> prepareForSaveExtended() method is the place to write that type of code. This method is called twice for each data source, first time before saving record, then after saving the record
You can write code like below for your validation and saving the records.
axCustable= _axBcStack.top(); switch (_recordProcessingContext)
{
// Ensure CustTable record is saved before any of its dependent child records
case AxdRecordProcessingContext::BeforeChildRecordProcessed:
switch (_childRecord.dataSourceName())
{
case #EarningStmtLine_DataSourceName:
if (!axCustTable.isProcessed())
{
if (this.checkCustTable())
{
this.prepareCustTable();
return true;
}
}
break;
}
return false;
// Ensure CustTable record is saved
case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:
if (!axCustTable.isProcessed())
{
return true;
}
return false;
}
return false;
How to default Value in the webservice?
Write the code for it in the Ax***** classes for your document. Use the parmMethods to do that. The code some thing like below will be good example
protected void setIsTestField()
{
if (this.isMethodExecuted(funcName(), fieldNum(TestTable, IsTestField))
{
return;
}
this.IsTestField(NoYes::No);
}
How to make fields not required or un mandatory on the web service?
If you have a field that is mandatory on the table but you want those fields to be not required on the class, you have to override the initMandatoryFieldExemptionList() on the Ax*** class. For instance, for custTable, over ride the method in AxCustTable class and write code like below
protected void initMandatoryFieldsExemptionList()
{
super();
this.setParmMethodAsNotMandatory(methodStr(AxTestTable, parmIsTestField));
}
How to make fields mandatory on the web service?
If you have a field that is not mandatory on the table but you want those fields to be required on the webservice, you have to override the initMandatoryFieldMap() on the AxD*** class. For instance, for custTable, over ride the method in AxDCustTable class and write code like below
Do we have reference group type functionality on the Web service?
If you have foreign key of some table in your document table, you probably don’t want that record id to be taken as input from the user, and you probably be looking for the user understandable value from him. For that type of functionality, you have to override the expandSurrogateKey(…) method on your Axd class and make a natural key on the foreign key table. This natural key would be shown to the user.
I want to write customized code that could resolve surrogate key ?
Over ride the getForiegnkeyValue (..) method on your Axd class and you can write code like below to resolve the references

ret = super(_axdBaseProperty, _sfkReplacementValue);
switch (_axdBaseProperty.parmImplementingTableId())
{
case tableNum(TestTable) :
switch (_axdBaseProperty.parmImplementingFieldId())
{
case fieldNum(TestTable, TestField):
ret = TestTable::Find(_sfkReplacementValue.value(‘TestNaturalKeyName’)).RecId).RecId;
break;
}
break;













