How to update the worknote of a change request from one ServiceNow to another ServiceNow instance?

User205031
Tera Contributor

Hi All,

I want to update worknote of a change request from one ServiceNow to another ServiceNow instance?

 

ServiceNow instance 1 is creating change request in ServiceNow instance 2 and now ServiceNow instance 2 wants to send some acknowledgement as ticket number in the worknotes to ServiceNow system 1.

 

For that I have created a Rest message:

User205031_0-1756112624819.png

 

I have created an after/update BR:

User205031_1-1756112664352.png

 

Code:

(function executeRule(current, previous /*null when async*/) {

    var body = {};
    var request = '';
    var url = "";
    var cor = current.getValue("correlation_id");
    gs.log('CorrelationID' + cor);
    if (current.work_notes.changes())
     var comment = current.work_notes.getJournalEntry(1);
     body = {

                "work_notes": current.getValue('number')    
        };
     request = 'Update comment';

     try {
        var req = new sn_ws.RESTMessageV2('Acknowledge AXON ticket', request);
        req.setStringParameterNoEscape('sys_id', current.getValue("sys_id"));
        //req.setEndpoint(url);
        req.setRequestBody(JSON.stringify(body));
        req.setAuthentication('basic', 'Axon API');
        var reqInt = req.execute();
        var requestBody = reqInt.getRequestBody();
        var responseBody = reqInt.getBody();
        var json = JSON.parse(responseBody);
        var httpStatus = reqInt.getStatusCode();
        gs.log('success response2:' + responseBody);
        gs.log("Response status code is2 " + httpStatus);
    } catch (ex) {
        var message = ex.message;
        gs.log('success response3:' + responseBody);
        gs.log("Response status code is3 " + httpStatus);
    }


})(current, previous);
 
I am getting below error:
success response2:{"error":{"message":"Standard Change Request not found","detail":""},"status":"failure"}
 
I am not able to pass the sys_id of the change request from ServiceNow instance 1.
Please help!
1 REPLY 1

GlideFather
Tera Patron

Hi @User205031,

 

if you have two different instances - then the sys ID will not be the same...

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */