AIF–handling related incoming records

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’)

 

 

HRMWebRecruitment            axbc_WebRecruitment;

HRMWebRecruitmentAttachments axbc_Attachments;

 

}

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)

{

 

case AxdRecordProcessingContext::BeforeChildRecordProcessed:

switch(_childRecord.dataSourceName())

{

case #Attachments_DataSourceName:

if(!axbc_WebRecruitment.isProcessed())

{

return true;

}

break;

}

return false;

 

// 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)

{

 

// Propagate parent’s key

case AxdRecordProcessingContext::BeforeAnyChildRecordsProcessed:

axbc_WebRecruitment = axbc_Attachments.parentAxBC();

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

return false;

 

// 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;

}