Philippsen's Blog

Everyday findings in my world of .net and related stuff

AIF–post processing of incomming record

Posted by Torben M. Philippsen on October 7, 2014

In a recent task for a customer I created a document service based on customized datamodel (build by myself). The datamodel consisted of two related tables. In these two tables I would collect incomming records from whicj I had to create CirParty entities, HRM applicants and HRM applications. This means that my datamodel would only serve the purpose of collecting the data. Then I would create some business logic to process the incoming logic. In Dynamics AX 2012 I searched for the right hookin and found that the UpdateNow method on the Axd class to fully fulfill my requirements.

I ended up with this peace of code…

ClassDeclaration:

class Axdegf_HRMWebRecruitment extends AxdBase

{

    #define.WebRecruitment_DataSourceName(‘WebRecruitment’)

    #define.Attachments_DataSourceName(‘Attachments’)

   

 

      //EG/2014.10.07/TOMPH, 00328407_3 HRMWebRecruitment—>

    AxEGF_HRMWebRecruitment            axbc_WebRecruitment;

    AxEGF_HRMWebRecruitmentAttachments axbc_Attachments;

    //EG/2014.10.07/TOMPH, 00328407_3 HRMWebRecruitment <–

}

PrepareForSaveExtended method (where the reference for the current record is created – marked in red):

public boolean prepareForSaveExtended(

    AxdStack                    _axBcStack,

    str                         _dataSourceName,

    AxdRecordProcessingContext  _recordProcessingContext,

    AxInternalBase              _childRecord)

{

    //TODO: Add code here to ensure that required fields specified in the initMandatoryFieldsMap method are sent in by the service caller.

    switch (_dataSourceName)

    {

        // ———————————————————————-

        // Process WebRecruitment records

        // ———————————————————————-

        case #WebRecruitment_DataSourceName:

 

            axbc_WebRecruitment = _axBcStack.top();

            switch (_recordProcessingContext)

            {

                //EG/2014.10.01/TOMPH, 00328407_3 HRMWebRecruitment –>

                case AxdRecordProcessingContext::BeforeChildRecordProcessed:

                    switch(_childRecord.dataSourceName())

                    {

                        case #Attachments_DataSourceName:

                            if(!axbc_WebRecruitment.isProcessed())

                            {

                                return true;

                            }

                            break;

                    }

                    return false;

                    //EG/2014.10.01/TOMPH, 00328407_3 HRMWebRecruitment <–

                // Ensure WebRecruitment record is saved

                case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:

                    if (!axbc_WebRecruitment.isProcessed())

                    {

                        return true;

                    }

                    return false;

            }

—-code left out—

UpdateNow method:

//EG/2014.09.21/TOMPH, 00328407_3 HRMWebRecruitment

//Meethod used to run busines logig before AIF ends its lifecycle

//Here we process the incoming record

public void updateNow()

{

    EGF_HRMWebRecruitment           egf_HRMWebRecruitment;   

    ;

    super();

    //get the current incoming record

    //egf_HRMWebRecruitment = axegf_HRMWebRecruitment.eGF_HRMWebRecruitment();

    egf_HRMWebRecruitment = axbc_WebRecruitment.eGF_HRMWebRecruitment();

    //having he incoming record – process it

    egf_HRMWebRecruitment.ProcessIncomingRecord();

}

Advertisements

Sorry, the comment form is closed at this time.

 
%d bloggers like this: