4.21.1 The ERP integration platform currently supports three types of custom functions
1. Fixed Input Parameter: Map syncArg

2. Fixed Return: return syncArg;
3. Custom Function Verification: as long as the custom function code contains one of Fx.object.create, Fx.object.batchCreate, Fx.object.update, Fx.object.batchUpdate and other strings, it means that the function body is in update/ Add/Obsolete calls.
Scenario: If the above string is added to the custom function (the string comment is invalid, it will also be detected) and contains the same string as the bound field apiName (the comment will also be detected), the strategy will not be enabled, and an abnormal function verification will be reported fail.
4. When new data is added: syncArg.objectData is the object master data, and syncArg.details is the object detail data
5. When the data is updated: syncArg.objectData may be the master object data or the slave object data, and it must be judged by objApiName
4.21.2 Custom function execution before synchronization supports data filter:
That is, the return result in the letter contains "isExec": "false", that is, the synchronization will not be executed in the future, and the target data will not be changed accordingly.
Test Scene: Add "isExec": "false" or "isExec":false to the Map returned by the custom function, and the target data will not change.
Function Code:
Map map = ["details":syncArg.details, "objectData":syncArg.objectData, "isExec":"false"];
return map;
4.21.3 Execute custom functions during synchronization:
After the function is executed, even if the mapping value written in the function is modified, the enterprise id and object apiName will not be changed.
Test Scene: Only new data will carry the slave object; when updating, the object mapping value will be updated, so if no special identification is made for the slave object, the updated object will not distinguish between the master and slave objects, and will be updated without exception. The name of the master and slave objects Will be updated for custom function assignment
Function Code:
log.info("Event type: " + syncArg.destEventType);
log.info(syncArg.objectData);
log.info(syncArg.details);
Map objectData = syncArg. objectData as Map;
objectData.name = "Custom function modification"
Map map = ["details":syncArg.details, "objectData":syncArg.objectData];
log. info(map);
return map;
4.21.4 Execute custom functions after synchronization:
After the function is executed, even if the mapping value written in the function is modified, the enterprise id and object apiName will not be changed.
Test Scene: data synchronization will not be affected, just pass the data to the custom function, you need to check the log to judge
Function Code:
Map map = ["details":context.details, "objectData":context.data, "afterSync" : "yes001"];
return map;
The specific entry fields (if you don’t know what fields the entry has, write the function first, and then print it for reference. Note that adding and updating entries are different) and function examples are as follows
Before synchronization: after passing the verification of the data range
Main entry fields:
{
"destObjectApiName": "",//target object apiName
"sourceData": {"field apiName":"field value"}//object field information
}
Simple example:
log.info(syncArg);
String destObjApiName=syncArg["destObjectApiName"] as String;
log.info("destObjectApiName:"+destObjApiName);
if("object_xo21i__c"==destObjApiName){
return syncArg;
}
Map objectData=syncArg["objectData"] as Map;
String customerCode=objectData["customerCodeHead"] as String;
syncArg["isExec"]=false;//Set this field to false, it will filter out this data out of sync
return syncArg;
Synchronizing: Before writing to the target system
Main entry fields:
{
"destDetailSyncDataIdAndDestDataMap": {"":{"field apiName":"field value"}}, //target object details
"destData": {"field apiName":"field value"}//target object field information
//If the newly added master object is in destData, the detailed data is in destDetailSyncDataIdAndDestDataMap, if the master-slave data is updated, both are in destData (the update is updated separately)
}
Simple example:
//Modify customerShortName field value
log.info(syncArg);
syncArg["objectData"]["customerShortName"]="dddddd"
log.info(syncArg);
return syncArg;
After synchronization: after writing to the target system
Main entry fields:
{
"sourceDataId": "5fead1146660700001170e3d",//source data id, only crm->erp direction has this field
"sourceObjectApiName": "AccountObj",//source object apiName
"completeDataWriteResult": {//The result of writing the target data
"detailWriteResults": [],//Detailed data results
"errCode": 0,
"success": true,
"destEventType": 1,
"errMsg": "success",
"writeResult": {//The main data result, the errCode is s106240000 success, other error codes returned by the failure interface
"errCode": 5001,
"success": false,
"syncDataId": "3ab1c2c2ffe04111b3e713632d5a4f76",
"errMsg": "Preprocessing service call error: Failed to call external http interface, error message: 100, SAP system BP name has been created, repeated creation is not allowed. ::errCode=s306240003",
"destDetailSyncDataIdAndDestDataMap": {}
}
},
"destObjectApiName": "AccountObj_1el03su6s",//target data object apiName
"objectData": {//object data
"tenant_id": "706089", //Enterprise ei
"object_describe_api_name": "AccountObj_1el03su6s",//object apiName
"_id": "5fead2696532bf0001e524e4"
},
"details": {},//Detailed data
}
Simple example:
//crm->erp, write the id of the target object to the crm source object
log. info(syncArg)
if(syncArg["objectData"]["id"]!=null&&syncArg["objectData"]["id"]!=""
&&syncArg["sourceDataId"]!=null&&syncArg["sourceDataId"]!=""){
String destDataId=syncArg["objectData"]["_id"] as String;//target data id
String sourceDataId=syncArg["sourceDataId"] as String;//source data id
String errCode=syncArg["completeDataWriteResult"]["writeResult"]["errCode"]as String;
log.info("--"+errCode)
if (errCode =="0"){//&&destDataId.length()<11
def (Boolean error,Map data,String errorMessage) =
Fx.object.update("AccountObj", sourceDataId,
["field_b25i7__c":destDataId],true);
log. info(errorMessage)
}
}
return syncArg;