I want to populate the work notes fields from SCTASK to RITM , need a BR for that.

posasaihimahars
Tera Contributor
 
2 REPLIES 2

Clara Lemos
Mega Sage
Mega Sage

Hello @posasaihimahars ,

 

You can configure a Business Rule on the Catalog Task Table (sc_task), as follow :

Screenshot 2023-11-15 at 11.25.06.png

 Then, in the Advanced Tab add the following script:

 

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

    var regex = new RegExp('\n');

    var ritm = new GlideRecord('sc_req_item');
    ritm.addQuery('sys_id', current.request_item);
    ritm.addActiveQuery();
    ritm.query();

    if (ritm.next()) {
        var sctaskWorkNotes = current.work_notes.getJournalEntry(1).trim();
        var ritmWorkNotes = ritm.work_notes.getJournalEntry(1).trim();

        var i = sctaskWorkNotes.search(regex);

        if (i > 0) {
            sctaskWorkNotes = sctaskWorkNotes.substring(i + 1, sctaskWorkNotes.length);
        }

        var c = ritmWorkNotes.search(regex);
        if (c > 0) {
            ritmWorkNotes = ritmWorkNotes.substring(c + 1, ritmWorkNotes.length);
        }

        if (ritmWorkNotes.indexOf(sctaskWorkNotes) == -1) {
            ritm.work_notes = sctaskWorkNotes;
            ritm.update();
        }
    }

})(current, previous);

 

If that helps please mark my answer as correct / helpful!
And if further help is needed please let me know

Cheers

Thank you Clara, 

This has helped me out and works as expected.  👍