Monday 24 October 2016

AIF AX2012 good to know concepts.

In this post I am trying to consolidate the concepts which are good to know and can help in making the right decision for deciding the approach of service creation and customization of existing ones.

1. Axd class methods.

  • getSurrogateForeignKeyValue() : This method is used for getting the surrogate key values for related table fields. Below is the example code snippet.

public RecId getSurrogateForeignKeyValue(AxdBaseProperty _axdBaseProperty, Struct _sfkReplacementValue)
{
RecId ret;
ret = super(_axdBaseProperty, _sfkReplacementValue);
switch (_axdBaseProperty.parmImplementingTableId())
{
case tableNum(DirpartyTable) :
switch (_axdBaseProperty.parmImplementingFieldId())
{
case fieldNum(DirpartyTable, Name):
ret = DirpartyTable::find(_sfkReplacementValue.value(fieldStr(DirPartyTable,Name))).RecId;
spTypeId = ret;
break;
}
}
return ret;
}
.
This method will be overridden in scenarios where the document service has a table which has multiple foreign key relations. As we know that we cannot pass the recId values directly, but certainly we may need to populate the foreign key values. Hence we can override this method and finds the related recId of the value passed for certain field.
sfkReplacementValue.value denotes the replacement key value mentioned on the related table.
  • UpdateNow(): This method is the last point  of execution in document service and is called during the create and update operations. This method is basically used when we have to perform any business logic on the created or updated entity. for ex: If I am using a document service to create a sales order in AX and my requirement is to confirm the same sales order while creation only. In this scenario I can write my business logic for sales order confirmation in updatenow() method.
  • expandSurrogateForeignKeys(): This method return true by default, which means that if there is any foreign key exist on the table than the framework can automatically convert the input for that field into replacement key. For ex: If I am creating a customer and my customer has a foreign key relation with custGroup. Now if this method is set to return true than it will take custGroupId as input and at backend find the surrogate key and associate it with RecId of custgroup record and populate the recId on custTable.
  • PrepareForSaveExtended(): This method is the entry point and is called in sequence with the data sources mentioned on the query in AX2012 R3. This method is very important with the customization point of view. We can include the value default logics, validations and custom field value handling in this method.
2. Terminology:  While going through the Axd classes, you can come across lot of terms which  are new, explaining few terms below which will help in understanding the code written in axdClasses.

  • AxdRecordProcessingContext: Record processing context is defined based on the data source levels defined on the document service query. Based this context Axd class proceed to create the records in child and parent tables. This term is basically found in prepareForSaveExtended method(). This method has been called multiple times when the record are processed in respective table. we can also define our custom code based on these contexts.
  • AxdRecordAction: This is another base enum which can be used for executing the particular logic based on the record action type. Record action type is defined by the operation which is triggered, basically there are create, read, update and delete operations. For ex. If wee need to perform some logic related to calculation of discount on a sales order if there is change in customer account. So, in order to update the customer account we will trigger the update operation. now we can place our code in prepareForSaveExtended() method below the relared processing context in following manner.
  if  (_axBcStack.top().recordAction() == AxdRecordAction::Update)
    {
      Perform your business logic and set parm value accordingly.

    }

In my next post I will demonstrate the difference between service operations and their relevance.





No comments:

Post a Comment