
I have successfully created code to change the Created By and Modified By fields when Sales Quotes are created in Microsoft CRM and imported into DAX 2012 so that the service account UserID is not used.
By running the following before insert:
new OverwriteSystemfieldsPermission().assert();
quotationTable.overwriteSystemfields(true);
quotationTable.(fieldNum(SalesQuotationTable, CreatedBy)) = userInfo.Id;
quotationTable.(fieldNum(SalesQuotationTable, CreatedDateTime)) = DateTimeUtil::getSystemDateTime();
quotationTable.(fieldNum(SalesQuotationTable, ModifiedBy)) = userInfo.Id;
quotationTable.(fieldNum(SalesQuotationTable, ModifiedDateTime)) = DateTimeUtil::getSystemDateTime();
CodeAccessPermission::revertAssert();
Problem now is when Sales Quotes are updated in CRM and those updates are pushed to DAX 2012, the updates reflect the service account UserID.
I tried the following prior to update:
new OverwriteSystemfieldsPermission().assert();
quotationTable.overwriteSystemfields(true);
quotationTable.(fieldNum(SalesQuotationTable, ModifiedBy)) = userInfo.Id;
quotationTable.(fieldNum(SalesQuotationTable, ModifiedDateTime)) = DateTimeUtil::getSystemDateTime();
CodeAccessPermission::revertAssert();
Can changes only be done during insert?
Why would it allow changes during insert and not be able to change modified by during updates?
Any feedback would be appreciated.
Thanks.
*This post is locked for comments
I have the same question (0)If you have the properties set on the table to populate those fields, whenever you do an update, the AX kernel will stamp the records after your update in a separate statement with the current userid and datetime. So even if you defined your values, that will be overwritten. If you want to always provide your own values, I am afraid you need to disable the settings on the table, however with that you lose tracking those values when you call a doUpdate(), or it is not coming through a scenario where you deliberately populate the values (your CRM import routine).
I would just create a custom created/modified by field and populate those, rather than bothering overriding system fields. You could also force populating the values in case of doInsert/doUpdate method calls if you place the logic to fill the fields for example in the aosValidate* methods, since that is always called.