Latest Additional comments are not getting insync from case to Incident

saibandaru
Giga Contributor

Customer comments are not syncing with the incident from the case. The scenario is: when Customer One creates a case and adds additional comments, those comments sync correctly with the incident. However, when Customer Two — who has the same roles — adds a comment to the case created by Customer One, the comments do not sync with the incident.

- We haven't customized any script to restrict users from adding additional comments during the sync process. However, we have customized a script to ensure that all the latest additional comments are synced from the case to the incident, provided the comments are not identical.

 

- Script used for sync b/w case to incident:

 

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here
    var inc = new GlideRecord('incident');
    if (inc.get(current.incident)) {
        var workNotes = current.comments.getJournalEntry(1).split("(Additional comments)");
        var inc_notes = inc.comments.getJournalEntry(1).split("(Additional comments)");
        if (inc_notes[1] == undefined && workNotes[1] == undefined) {
            inc.comments += workNotes;
            inc.update();
        } else if (inc_notes[1].trim() != workNotes[1].trim()) {
            //cs.work_notes += "-" + workNotes;
            inc.comments += workNotes[1];
            inc.update();

        }
    }
})(current, previous);
5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

@saibandaru 

there is OOTB query business rule on incident table which must be blocking when you use GlideRecord

That could be the reason

Update as this -> use setWorkflow(false) to restrict BR from running

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here
    var inc = new GlideRecord('incident');
    inc.addQuery('sys_id', current.incident);
    inc.setWorkflow(false); // disable the query business rule
    if (inc.next()) {
        var workNotes = current.comments.getJournalEntry(1).split("(Additional comments)");
        var inc_notes = inc.comments.getJournalEntry(1).split("(Additional comments)");
        if (inc_notes[1] == undefined && workNotes[1] == undefined) {
            inc.comments += workNotes;
            inc.update();
        } else if (inc_notes[1].trim() != workNotes[1].trim()) {
            //cs.work_notes += "-" + workNotes;
            inc.comments += workNotes[1];
            inc.update();

        }
    }
})(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

Hi Ankur,

Thanks for the Response, but it didn't worked out for me

@saibandaru 

we also faced similar issue earlier and it was resolved using this.

Did you check if business rule triggered or not?

I added logs, please share what came

(function executeRule(current, previous /*null when async*/ ) {
    // Add your code here
    var inc = new GlideRecord('incident');
    inc.addQuery('sys_id', current.incident);
    inc.setWorkflow(false); // disable the query business rule
    if (inc.next()) {
		gs.info('Inside IF');
        var workNotes = current.comments.getJournalEntry(1).split("(Additional comments)");
        var inc_notes = inc.comments.getJournalEntry(1).split("(Additional comments)");
        if (inc_notes[1] == undefined && workNotes[1] == undefined) {
			gs.info('Inside comments');
            inc.comments += workNotes;
            inc.update();
        } else if (inc_notes[1].trim() != workNotes[1].trim()) {
			gs.info('Inside Else IF');
            //cs.work_notes += "-" + workNotes;
            inc.comments += workNotes[1];
            inc.update();

        }
    }
})(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

Hi Ankur,

Same with this kind of logs, it didnt worked out for me

Thanks

Sai kiran