Announcing the Global SNUG Board of Directors. Learn more here

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tiagomacul
Mega Sage
Mega Sage

Script::. How to update a change_request

 

var objChangeRequest = new GlideRecord("change_request");

objChangeRequest.addQuery("sys_id", "bfb14d900fa0d74032854d6a42050e38");
objChangeRequest.orderByDesc('sys_created_on');
objChangeRequest.query();
objChangeRequest.next();
		
objChangeRequest.state.setValue("3");

objChangeRequest.setWorkflow(false);
objChangeRequest.autoSysFields(false); 
objChangeRequest.update(); 

 

Know-More-Now-Logo.jpg

More documents

 

Comments
Nick65
Mega Expert

Not sure about this one a better/more concise way to update any record in the system ,

var gr = new GlideRecord('change_request');
if(gr.get('e9ef98dbdb545700ede2fb671d961958')){
gr.state.setValue("3");
gr.update();

Also since you are targeting one record with "objChangeRequest.addQuery("sys_id", "bfb14d900fa0d74032854d6a42050e38");

There really isn't any reason to use orderByDesc("sys_created_on");

  • Also you should be wrapping your next() method in an if or while statement to prevent any unneeded code from running.

Also you should mentioned that using, 

objChangeRequest.setWorkflow(false);
objChangeRequest.autoSysFields(false);

Will prevent other Business rules from running and system fields not being updated. To avoid new developers from being mislead or confused by the use of these methods.

 

Version history
Last update:
‎02-23-2018 11:09 AM
Updated by: