Usage of GlideRecord.update()

The SN Nerd
Giga Sage
Giga Sage

Hi Community,

The ServiceNow Product documentation for the update function in a GlideRecord is as follows:

find_real_file.png

As far as I can tell, the reason parameter doesn't seem to do anything despite the documentation.

When I open up the audit history for an update where parameter was called, there is no trace.

Example:

if ( isAnyChildTaskPending() ) {

  grParent.state = PENDING_STATE;

} else {

  grParent.state = WORK_IN_PROGRESS_STATE;

}

if (grParent.state.changesFrom(previousState)) {

  grParent.work_notes = 'Status changed automatically by system to reflect overall status of the request.';

  grParent.update('Automation');

}

There is no trace of the 'Automation' in the audit logs that I can find.

find_real_file.png

I traced it to the sys_audit record - still no reason.

find_real_file.png

Does the reason parameter actually do anything?

This could be quite useful for tracing automation to business rules.

Thanks,

Paul


ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

gr.update(reason) does not populate the reason field on the sys_audit record when using task.



This works:


var current = new GlideRecord( 'sc_task' );  


current.get('cbbd39274f29f2008d2f87501310c777');  


current.state = '2';


current.update('Reason');



This does not work:


var current = new GlideRecord( 'task' );  


current.get('cbbd39274f29f2008d2f87501310c777');  


current.state = '2';


current.update('No reason');



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

View solution in original post

6 REPLIES 6

Carl Fransen1
Tera Guru

Hi Paul,



Although I can't help you with your specific issue - I found this link the other day when looking for assistance myself with GlideRecords.



https://www.servicenowguru.com/scripting/gliderecord-query-cheat-sheet/



Hopefully it's of some help to you!



Cheers


Carl.


The SN Nerd
Giga Sage
Giga Sage

gr.update(reason) does not populate the reason field on the sys_audit record when using task.



This works:


var current = new GlideRecord( 'sc_task' );  


current.get('cbbd39274f29f2008d2f87501310c777');  


current.state = '2';


current.update('Reason');



This does not work:


var current = new GlideRecord( 'task' );  


current.get('cbbd39274f29f2008d2f87501310c777');  


current.state = '2';


current.update('No reason');



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022