Change co relation number not updating

Anandkumar g
Tera Contributor

Hello 

 

I have used Rest API servicenow to servicenow Integration 

 

I used the below code for change Co relation updates, but it's not updating if I try to update this change type changed in Emergency change. Please help me to fix this issue

=======================================================================

(function executeRule(current, previous /*null when async*/ ) {
    var asmnt_grp = current.getDisplayValue('assignment_group');
    var queue = current.getDisplayValue('u_queue');
    var ebond;
    var flag = '';
        if (current.comments.changes() && current.work_notes.changes())
            flag = 'comments_notes';
        else if (current.work_notes.changes())
            flag = 'notes';
        else if (current.comments.changes())
            flag = 'comments';
        if (current.correlation_display.toString() == '') {
            ebond = new genericEbondingUtil().initiateEbonding(current.sys_class_name, current, 'insert', current.number.toString(), flag);

            // updates of ot corelation number
            current.correlation_display= JSON.parse(ebond).result.number;
            current.correlation_id=JSON.parse(ebond).result.sys_id;
            current.update();
        } else {
            ebond = new genericEbondingUtil().initiateEbonding(current.sys_class_name, current, 'update', current.number.toString(), flag);
        }
   
})(current, previous);

 

=============================================================

 

Thanks in Advance

5 REPLIES 5

Anandkumar g
Tera Contributor

I used this code for co-relation CR update

 

  current.correlation_display= JSON.parse(ebond).result.number;
            current.correlation_id=JSON.parse(ebond).result.sys_id;
            current.update();

Ankur Bawiskar
Tera Patron
Tera Patron

@Anandkumar g 

so what came in API response?

Did you print that?

try this and share logs

(function executeRule(current, previous /*null when async*/ ) {
    var asmnt_grp = current.getDisplayValue('assignment_group');
    var queue = current.getDisplayValue('u_queue');
    var ebond;
    var flag = '';

    // Add logging for debugging
    gs.log("Assignment Group: " + asmnt_grp);
    gs.log("Queue: " + queue);

    if (current.comments.changes() && current.work_notes.changes()) {
        flag = 'comments_notes';
    } else if (current.work_notes.changes()) {
        flag = 'notes';
    } else if (current.comments.changes()) {
        flag = 'comments';
    }

    gs.log("Flag: " + flag);

    if (current.correlation_display.toString() == '') {
        ebond = new genericEbondingUtil().initiateEbonding(current.sys_class_name, current, 'insert', current.number.toString(), flag);
        gs.log("Ebond Insert Response: " + ebond);

        // updates of correlation number
        var ebondResult = JSON.parse(ebond).result;
        current.correlation_display = ebondResult.number;
        current.correlation_id = ebondResult.sys_id;
        current.update();
        gs.log("Correlation Display: " + current.correlation_display);
        gs.log("Correlation ID: " + current.correlation_id);
    } else {
        ebond = new genericEbondingUtil().initiateEbonding(current.sys_class_name, current, 'update', current.number.toString(), flag);
        gs.log("Ebond Update Response: " + ebond);
    }
})(current, previous);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ebond Insert Response:

 

Anandkumarg_0-1745850993150.png

 

Correlation Display:
Anandkumarg_1-1745850993135.png

 

 
Anandkumarg_2-1745850993148.png

 

Ebond Update Response:

 

Anandkumarg_3-1745850993121.png

 

 

I received multiple updates

Anandkumar g
Tera Contributor
Ebond Insert Response:

 

Anandkumarg_0-1745846853588.png

Correlation Display:
Anandkumarg_1-1745846967409.png
 
Anandkumarg_3-1745847033190.png

Ebond Update Response:

 

Anandkumarg_2-1745847025488.png

 

I received multiple updates