The CreatorCon Call for Content is officially open! Get started here.

Request rejected comments into a notification

jrhoads
Giga Contributor

Hello All,

I could use some help. I have been trying to get a rejected notification email to include the approver's rejection comments.   I have tried several scripts to get his to work without fruitful results. The notification is targeting the sysapproval_approver table.

I tried the tree picker and then previous articles on the community to find an answer that works.

var gr = new GlideRecord('sysapproval_approver');

gr.addQuery('sysapproval', current.sys_id);

gr.addQuery('comments', current.comments);

gr.query();

if(gr.next()){

  template.print("Rejected comments: " + gr.comments.getJournalEntry(1);

}

Thanks for any help.

1 ACCEPTED SOLUTION

twright5
Kilo Expert

Try removing the gr.addQuery('comments;, current.comments);


once you return from the query(), then just get the comments.



var gr = new GlideRecord('sysapproval_approver');


gr.addQuery('sysapproval', current.sys_id);


gr.addQuery('comments', current.comments); Remove this line


gr.query();


if(gr.next()){


  template.print("Rejected comments: " + gr.comments.getJournalEntry(1);


}



If you still have trouble getting the comments, try setting getJournalEntry to -1;



Tom


View solution in original post

6 REPLIES 6

nortonxnorris
Giga Expert

The route I took was:


1: The rejection note was added to the comments field.


2: Copy the contents of the comments field to the work note field of the parent.


3: Send a notification, when work_notes changes.



If you would like to use this, here is the script:


Condition: current.comments.changes() && (!current.sysapproval.isNil()) && current.sysapproval.sys_class_name == 'change_request'



Script:


var gr = new GlideRecord('change_request');


gr.get(current.sysapproval);


gr.work_notes = current.comments;


gr.update();


Thank you, but I may not be able to get the process you suggest to fly with my superiors. They want to keep work notes separate from the rejection comments.


twright5
Kilo Expert

Try removing the gr.addQuery('comments;, current.comments);


once you return from the query(), then just get the comments.



var gr = new GlideRecord('sysapproval_approver');


gr.addQuery('sysapproval', current.sys_id);


gr.addQuery('comments', current.comments); Remove this line


gr.query();


if(gr.next()){


  template.print("Rejected comments: " + gr.comments.getJournalEntry(1);


}



If you still have trouble getting the comments, try setting getJournalEntry to -1;



Tom


jrhoads
Giga Contributor

Thanks Tom.


I set it up as a new email script:



var gr = new GlideRecord('sysapproval_approver');


gr.addQuery('sysapproval', current.sys_id);


gr.query();


if(gr.next()){


  template.print("Rejection comments: " + gr.comments.getJournalEntry(1));


}



Then referenced it in the notification body:


${mail_script:rejected_comments_from_journal_entry}