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

James Chun
Kilo Patron

Hey @Ana39,

 

You can write a simple Business Rule for it, e.g.

JamesChun_0-1709668519504.png

 

Script:

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

	// Add your code here
	var parentGr = new GlideRecord('sc_req_item');
	parentGr.get(current.getValue('request_item'));
	parentGr.work_notes = 'Some notes here';
	parentGr.update();
	

})(current, previous);

 

Hope it helps, cheers

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

@Ana39 did you get a chance to look at my solution ?

 

Thanks 

Swathi 

the code ended to be: 
 
(function executeRule(current, previous /*null when async*/ ) {

    var parentSysId = current.parent;
    var fieldchanges = current.state.getDisplayValue(); // get state
    var grPTPCRequest = new GlideRecord('tablename');
    grPTPCRequest.addQuery('sys_id', parentSysId);
    grPTPCRequest.setLimit(1);
    grPTPCRequest.query();

    if (grPTPCRequest.next()) {
        grPTPCRequest.work_notes = "Update in task #" + current.number + ".  State is now " + fieldchanges;
        grPTPCRequest.update();
    }

})(current, previous);