Skip to main content

Notifications

Community site session details

Community site session details

Session Id :

How to develop inbound web service in ax 2012

Fawad Hassan Profile Picture Fawad Hassan 337

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;



This was originally posted here.

Comments

*This post is locked for comments