Dynamically Need to Update records in bulk from servicenow to Salesforce

Priya Gautum
Kilo Guru

Hi There,

 

I am trying to update the record in bulk from ServiceNow to Salesforce.

Here is the link I got, but I am unsure how to pass values dynamically as I am getting errors when I see logs.

  var responseput = {};
        for (var i = 0; i < parsed.length; i++) {
			gs.log('Get the response patch for attribute:0 '+ responseput);
            var IDs = parsed[i].Id.toString();
            if (responseput != '') {
                responseput = responseput + ',' + {
                    "attributes": {
                        "type": "OrderItem"
                    },
                    "id": IDs,
                    "Pending_Sync__c": false
                };
            } else {
                responseput = {
                    "attributes": {
                        "type": "OrderItem"
                    },
                    "id": IDs,
                    "Pending_Sync__c": false
                };
            }

       var oauthtoken = this._getAccessToken();
        var endpoint0 = "https://domain--######my.salesforce.com/services/data/v56.0/composite/sobjects";
		var req3 = Idfinal;
        var request2 = new sn_ws.RESTMessageV2();
        request2.setHttpMethod('PATCH');
        request2.setEndpoint(endpoint0);
        request2.setRequestHeader("Content-Type", "application/json");
        request2.setRequestHeader("Authorization", "Bearer " + oauthtoken);
        request2.setRequestBody(JSON.stringify(req3));
	gs.log('Get the response patch for attribute:1 '+ responseput);
        var response2 = request2.execute();

logs:

Get the response patch for attribute:1 [object Object],[object Object]

 

2 REPLIES 2

DYCM
Mega Sage

in javascript you will need to use:

JSON.stringify to convert JSON object to string

JSON.parse to convert string to JSON object

Mathieu Lepoutr
Mega Guru

Hi

 

You have to use the code from DYCM to solve this, he was 1 step ahead of me!

 

Why don't you let a decentralized integration solution, where you can granuarly decide which data will be send over, do the trick? 

With the included groovy scripting and error handling, you will be able to do this exact use-case.