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

arron_ubhi
ServiceNow Employee
ServiceNow Employee

Hi Paul,



Thank you for your post.



Can you confirm if you have added in the "Reason" field to the form layout on the sys_audit table? Based on the screenshot you have provided, I am unable to see the "Reason" field on the form



You can do this via the following:



1. Navigate to sys_audit.list on the navigation bar on the instance



2. Right-click > Form Layout and select "Reason", then click "Save"



Best Regards,



Arron


Sorry, I should mention that the reason field is empty.


As far as I can remember, adding a parameter to 'update' has never been reflected in the reason field.



Maybe this is a long time bug?



find_real_file.png



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

This worked perfectly for me. I wasn't aware of this functionality but I'll certainly use it!


var gr = new GlideRecord( 'incident' );


gr.get( 'sys_id', '53adb1e3dbed76005587f7951d961916' );


gr.short_description = 'new';


gr.update( 'solid reason, mate' );




Screen_Shot_2017-03-22_at_7_26_34_PM.png



Might be worth a HI ticket at this point...


I ran your code and confirm it works.



However, my code definitely is not.



I even copied the business rule into a background script and executed it, and the reason field is still empty.



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