Friday, October 21, 2022

Look up method on D365FO form control for cross company relationship


    [FormControlEventHandler(formControlStr(SystemParameters, ARTaxParametersGrid_TaxGroup), FormControlEventType::Lookup)]

    public static void ARTaxParametersGrid_TaxGroup_OnLookup(FormControl sender, FormControlEventArgs e)

{

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(TaxGroupHeading),sender);

Query query = new Query();

IntARTaxParameters arTaxParm = sender.formRun().dataSource(formDataSourceStr(SystemParameters,IntARTaxParameters)).cursor();    

QueryBuildDataSource qbdsTaxGroupHeading = query.addDataSource(tableNum(TaxGroupHeading));

        qbdsTaxGroupHeading.company(strFmt(arTaxParm.LegalEntityDataAreaId));

qbdsTaxGroupHeading.relations(true);

        qbdsTaxGroupHeading.addRange(fieldNum(TaxGroupHeading,DataAreaId)).value(arTaxParm.LegalEntityDataAreaId);

sysTableLookup.addLookupfield(fieldNum(TaxGroupHeading,TaxGroup));

    sysTableLookup.parmQuery(query);

    sysTableLookup.performFormLookup();

FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;

//cancel super() to prevent error.

 ce.CancelSuperCall();

}

Wednesday, August 17, 2022

Dual Write - Force records synchronization

Was going through with colleague on another implementation of DualWrite and noticed there was nothing online to force synchronization of records from FO to CE.

This could be useful when you want to synchronise one entity based on an event on another table. So if you want to synch a specific projtable:


List                            projEntityrecordsToSync =   new List(Types::AnyType);


ProjTableEntity projTableEntity;

select firstonly projTableEntity

                where projTableEntity.recid == projtable.RecId;

projEntityrecordsToSync.addEnd(projTableEntity);

DualWriteSyncHelper::forceSyncRecordsToCDS(projEntityrecordsToSync);

Friday, June 10, 2022

D365 Dual Write FO/PSA Project integration for Project Stage in FinOps and Active/Inactive in CE.

We recently had a requirement to integrate projects between D365 Finance and Operations and D365 CE/PSA. 

In CE/PSA every table record can be active/inactive which is controlled by this logic Understanding StateCode, StatusCode, Status and Status Reason in Dynamics 365 - Carl de Souza. Looking at the article, you can see that the active/inactive is controlled by two fields statusCode and statusReason, which meant, dualWrite OData needs to send the value for both fields.

In D365 FO, you can have enum based project stage as Created,Estimated,InProcess,User1,User2,User3,Completed.

Now, say we want the project in FinOps with a status InProcess and User2 (Investigating) to be treated as active in D365 CE and all other as inactive, we have to map the value to the equivalent enum for both StatusCode and also StatusReason.


For StateCode (Project Status), we map in the following way.



Here is a JSON for easy copy paste

[
{
"transformType": "ValueMap",
"valueMap": {
"created": "1",
"estimated": "1",
"inProcess": "0",
"user1": "1",
"user2": "0",
"user3": "1",
"completed": "1",
"active": "0",
"inactive": "1",
"scheduled": "0"
}
}
]

Similary, the mapping with statusCode (Status Reason) will look like below.

Here is a json for status reason for easy copy paste.
[
{
"transformType": "ValueMap",
"valueMap": {
"created": "2",
"estimated": "2",
"inProcess": "1",
"user1": "2",
"user2": "1",
"user3": "2",
"completed": "2",
"active": "1",
"inactive": "2",
"scheduled": "1"
}
}
]


Hope it makes it clear for others as I could not find any documentation on these and the only way I could find this was randomly firing different values to CE using postman.