4.1 [Function Components] Functions before, during, after Synchronization

1. 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;

2. 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;

3. 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;

4. Log in to webapi of k3 to Get Data

//Define request parameters, url, username, password, data center String url = "";//http://jxsz.fortiddns.com:58000/k3cloud/ String userName = ""; String passWord = ""; String acctId = "";//62415a905fb572 // request header Map headMap = ["Content-Type":"application/json"]; //Kingdee k3c login authorization processing, login authorization requires parameters: URL address, login user name, password, language, data center ID, calling method name String login = "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc"; //query interface method String queryMethod = "Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc"; Map bodyMap1 = [:]; // return structure Map returnMap = [:]; bodyMap1. put("lcid", "2052"); bodyMap1. put("userName", userName); bodyMap1.put("passWord", passWord); bodyMap1.put("acctId", acctId); StringBody body = StringBody.builder().content(bodyMap1).build() Request request = Request. builder() .method("POST") .url(url+login) .timeout(7000) .retryCount(0) .header("Content-Type","application/json") .body(body) .build() def(Boolean error1, HttpResult data1, String errorMessage1) = Fx.http.execute(request); if(error1){ log.info("Calling the login interface is abnormal: "+errorMessage1) } //Get kdservice-sessionid and ASP.NET_SessionId from the login result Map headers = data1["headers"] as Map; if(headers==null){ Fx.message.throwErrorMessage("Login failed: "+data1); } String Cookies = headers["Cookies"] as String; log.info("Cookies are"+Cookies); String sessionid=Cookies. split(";")[0]; String NET_SessionId=Cookies. split(";")[1]; sessionid=sessionid. split("=")[1]; NET_SessionId=NET_SessionId. split("=")[1]; // request body Map bodyMap = [:]; // return the maximum number of rows Integer TopRowCount=0; //Field key collection to be queried String FieldKeys="FCUSTID,FNumber"; //Business object form Id, String FormId="BD_Customer"; //Query conditions String FilterString="FNumber != ''"; //maximum number of rows Integer Limit=10; // start row index Integer StartRow=0; //combination parameters //Combined query condition parameters Map data = ["TopRowCount":TopRowCount,"FieldKeys":FieldKeys,"FormId":FormId,"FilterString":FilterString,"Limit":Limit,"StartRow":StartRow]; bodyMap. put("data", data); //Query data StringBody body1 = StringBody.builder().content(bodyMap).build() Request request1 = Request. builder() .method("POST") .url(url+queryMethod) .timeout(7000) .retryCount(0) .header("Content-Type","application/json") .header("kdservice-sessionid",sessionid) .header("ASP.NET_SessionId", NET_SessionId) .body(body1) .build() //log.info(url+method); def(Boolean error, HttpResult Result, String Message) = Fx.http.execute(request1); log.info("The returned data information is: "+Result); // start processing data String contentStr = Result["content"] as String; if(contentStr){ //Query failed if(contentStr. contains("ResponseStatus")){ Fx.message.throwErrorMessage(contentStr); } // Start processing if there is data, skip if the return is empty List contentList = Fx.json.parseList(contentStr); log.info("contentList: "+contentList); String[] keyList = FieldKeys. split(","); contentList. each { item -> List eachDataList=item as List; log.info("eachDataList:"+eachDataList) Map eachData=[:] //Each piece of data eachDataList.eachWithIndex{ value, int i -> eachData.put(keyList[i], value) } log.info("eachData:"+eachData) } }
2023-02-23
0 0