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.

What is right way of providing update reason?

Igor Kozlov
Tera Expert

Hello.

GlideRecord wiki page tells

public string update(Object reason)

Parameters: reason - Takes a string designating the reason for the update if necessary. The reason will be displayed in the audit record.

So what is right way of providing reason?

Neigher

var gr = new GlideRecord('alm_hardware');

gr.get('0034748c0ffc02003685ee68b1050e70');

gr.setForceUpdate(true); //just to make sure

gr.comments = 'test123'

gr.update("reason text her")

no

var gr = new GlideRecord('alm_hardware');

gr.get('0034748c0ffc02003685ee68b1050e70');

gr.setForceUpdate(true); //just to make sure

gr.comments = 'test1232'

var reason = {'reason' : 'some reason here'}

gr.update(reason)

works for me.

Thanks.

1 ACCEPTED SOLUTION

Jim Coyne
Kilo Patron

Both hard-coded strings and string variables will work (although your first example is not a string but a JavaScript object).   However, the reason is NOT added to the History table (sys_history_line), which the Activity Formatter uses to display in the form, but it is added to the Sys Audit table (sys_audit), which is not really shown anywhere.   You'll probably have to personalize your list view to add the Reason column.



It's definitely a little misleading.


View solution in original post

8 REPLIES 8

Deepa Srivastav
Kilo Sage

try only gr.update(); or



var reason='try';


gr.update(reason);



Also is audit on for that table .?


Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


only gr.update() will not give me the reason.it will just write changes to history



Deepa Srivastava wrote:



Also is audit on for that table .?


Table dictionary entry has audit option ticked


And there is picture of history changes for


var gr = new GlideRecord('alm_hardware');


gr.get('0034748c0ffc02003685ee68b1050e70');


gr.comments = 'some new coments'


var reason='try';


gr.update(reason);



find_real_file.png


Hi,



With gr.update() method you will update the current record of that table to which it has queried.


And if you use gr.update('some reason mentioned'); this will update with the reason mentioned in the audit table.


If this need not be tracked via history table you can add


autoSysFields(false);



Thanks and Hope it helps.


Jim Coyne
Kilo Patron

Both hard-coded strings and string variables will work (although your first example is not a string but a JavaScript object).   However, the reason is NOT added to the History table (sys_history_line), which the Activity Formatter uses to display in the form, but it is added to the Sys Audit table (sys_audit), which is not really shown anywhere.   You'll probably have to personalize your list view to add the Reason column.



It's definitely a little misleading.