Philippsen's Blog

Everyday findings in my world of .net and related stuff

AIF–handling related incoming records

Posted by Torben M. Philippsen on October 7, 2014

In a recent task for a customer I had to being able to handle HRM applicants and applications from a corparate website. In basics the customer wanted to have a webform where the applicant could enter his/her personal data and attach files like eg. a CV, the application or any other relevant stuff.

To handle that scenario I created two tables in AX – one to handle the applicant and application related stuff and another to handle the file attachments. One application should be able to have many attachments. Therefore the first attachment should relate to one application and the second attachment to the same application and so on…

Having the datamodel set, I created a document service.

I created a simple webform in c# that consumed the AIF service and I was soon able to send data into AX. Then it occured to me, that I wasn’t able to create the relation between attachments and applications from the webclient because I needed the RecID og the Application in order to put in onto the attachments.

Inside ax i found the PrepareForSaveExtended method of my AXD class to be useful. Here I could make sure that applications would be processed before attachments. And once the applications were processed I could fetch the RecId and put in on each attachment.

I ended up with this:

Class declaration:

 

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:

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;

            }

            return false;

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

        // Process Attachments records

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

        case #Attachments_DataSourceName:

 

            axbc_Attachments = _axBcStack.top();

            //axbc_Attachments.parmDescription("dudelidut");

            switch (_recordProcessingContext)

            {

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

                // Propagate parent’s key

                case AxdRecordProcessingContext::BeforeAnyChildRecordsProcessed:

                        axbc_WebRecruitment = axbc_Attachments.parentAxBC();

                        axbc_Attachments.parmHRMWebRecruitmentRecIdRef(axbc_WebRecruitment.currentRecord().RecId);

                        return false;

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

 

                // Ensure Attachments record is saved

                case AxdRecordProcessingContext::AfterAllChildRecordsProcessed:

                    if (!axbc_Attachments.isProcessed())

                    {

 

                        return true;

                    }

 

                    return false;

            }

            return false;

 

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

        // Unsupported data sources

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

        default:

            error(strfmt("@SYS88979",classId2Name(classidget(_axBcStack.top()))));

            return false;

    }

    return false;

}

 

Advertisements

2 Responses to “AIF–handling related incoming records”

  1. Darshana Parnaik said

    Hi, Torben M. Philippsen

    I have same requirement…
    i.e i want to attach CV in .net application for Applicant and i have created document service for create applicant in ax 2012. Then how to attach CV to that specific applicant.
    Please can you help me or share……..

    Thanks,
    Darshana

    • Hi Darshana,

      What tables is your document service based on?
      In my scenario I found it easier to create my own two custom tables that were designed to only contain relevant info from the web client. I would then hook into the AIF framework and redirect the incoming data to the respective hrm tables. In that way my custom tables would also work as log tables, which I find very useful.

      If your approach is to use the standard hrm tables directly in the document service, then you should look up information on how to enable document handling in that scenario. I can’t help you with, since I haven’t tried that myself. Another approach would be to create a custom service.

      If you are using the same approach as I, then just send me a few lines describing what your challenges are exactly, and I will be happy to try and assist you.

      Regards Torben

Sorry, the comment form is closed at this time.

 
%d bloggers like this: