Update parent activity log with task state

Ana39
Tera Contributor

Hi there, I am developing a new project in a custom table. I have a child task to the ticket and there is required to add a work note in the parent ticket, every time the child task state changes, 
It is only the task state updates that are required to be added as work notes in the activity log of the parent custom ticket.

Thanks in advance! 

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage
Giga Sage

Hi @Ana39 ,

 

replace sc_task with child table and sc_req_item with parent table

 

You can create before update business rule on sc_task table ,

swathisarang98_0-1709674241002.png

swathisarang98_1-1709674269294.png

 

 

 

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

    // Add your code here
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('sys_id', current.getValue('request_item'));
    gr.query();
    while (gr.next()) {
        // gr.work_notes =current.state;
		gr.work_notes.setJournalEntry(current.getDisplayValue('state'));
		gr.update();
    }

})(current, previous);

 

 

Updated code:

 

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

    // Add your code here
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('sys_id', current.getValue('request_item'));
    gr.query();
    while (gr.next()) {
        // gr.work_notes =current.state;
		gr.work_notes.setJournalEntry("SC task "+current.number+" state has been changed to "+"'"+current.getDisplayValue('state')+"'");
		gr.update();
    }

})(current, previous);

 

 

Result: In Ritm Table

swathisarang98_0-1709678711855.png

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

8 REPLIES 8

Harish KM
Kilo Patron
Kilo Patron

Hi @Ana39 To do this you would need to create a After Update BR on child table with

condition: State Changes AND

                  Worknote Changes

HarishKM_0-1709689102612.png

and then below script

Script:

var workNotes = current.work_notes.getJournalEntry(1); // get latest worknotes
var comm= new GlideRecord('parentTableName');
comm.addQuery('sys_id', current.parent);// ensure there is a field on your child table which holds Parent reference record
comm.query();
if(comm.next()){
comm.work_notes = "workNotes Updated " +workNotes;// map the worknotes to parent field
comm.update();
}
Regards
Harish

Hi @Ana39 if my response helped you please accept my Solution or let me know if you still have any issues. Happy to assist 

Regards
Harish

Ana39
Tera Contributor

Hi Harish, I will as soon as it works, it is not working right now 😓

Hi @Ana39 can you share what is not working? I may assist to fix the issue

Regards
Harish