Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

retrieving value from comments field in sysapproval table.

Chinmayee1
Giga Contributor

when the approver approves ,he enters a unique code in the comment and i need to retrieve that value and update in a new field in ritm table.

its journal input type and it shows my name ,time stamp and then the value appended.

i tried both -1 and 1.

how do i get only the value input by the approver 

 

 

3 REPLIES 3

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

That should work. Here is an example I tested it with. The sysID is from an approval record:

 

var sys = '00e9c07adba52200a6a2b31be0b8f5ae';

var current = new GlideRecord('sysapproval_approver');
current.get(sys);

gs.debug(current.comments.getJournalEntry(1));

 

//Gƶran

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

var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval', current.sys_id);
gr.query();
if(gr.next())
{
current.u_application_ci_name = gr.comments.getJournalEntry(-1);
gs.log('comments approval :'+gr.comments.getJournalEntry(-1));
gs.log('comments approval :'+gr.comments.getJournalEntry(1));
}

// Add your code here

})(current, previous);

 

I entered "test1" in comments field

logs

------------

comments approval :2018-10-28 18:10:03 - Chinmayee Mishra (Comments)test1

 

Ahh, sorry, missed that you just wanted the value. Then we need to trim down the string abit. this should work:

var sys = '00e9c07adba52200a6a2b31be0b8f5ae';

var current = new GlideRecord('sysapproval_approver');
current.get(sys);

var com = current.comments.getJournalEntry(1);

gs.debug("Value is " + com.substring(com.indexOf('(Comments)')+10).trim());//Finds where (Comments) is and add 10 characters since (Comments) is 10 characters. Then take the rest of the string

 

 

//Gƶran