Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

i want to change the read only field value through background script? please share me script ?

Rajesh98
ServiceNow Employee

i want to change the read only field value through background script? please share me script

1 ACCEPTED SOLUTION

hvrdhn88
Giga Patron

Sample Update code:

var gr  = new GlideRecord('incident');

gr.get('06743b65dbe277c0e4d95740cf9619c5'); //SYSID OF THE RECORD.

gr.short_description ='Test'; //assuming short description is read only field

gr.update();

 

Note: this is sample code to update the record column.

 

View solution in original post

4 REPLIES 4

AbhishekGardade
Tera Sage

which value you want to change? On which table?

Example:
var grCI = new GlideRecord('cmdb_ci'); grCI.addQuery('name','=','SAP WEB03'); grCI.query(); gs.print('grCI Query: ' + grCI.getEncodedQuery() + ' = ' + grCI.getRowCount()); while (grCI.next()){ grCI.asset_tag='ServiceNow '; grCI.update(); }
Refeence:
https://developer.servicenow.com/blog.do?p=/post/training-scriptsbg/
https://developer.servicenow.com/blog.do?p=/post/training-scriptsbg/

Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade

Thank you,
Abhishek Gardade

hvrdhn88
Giga Patron

Sample Update code:

var gr  = new GlideRecord('incident');

gr.get('06743b65dbe277c0e4d95740cf9619c5'); //SYSID OF THE RECORD.

gr.short_description ='Test'; //assuming short description is read only field

gr.update();

 

Note: this is sample code to update the record column.

 

Alikutty A
Tera Sage

Hi,

You can try this after replaceing table and field names.

var gr = new GlideRecord("You table name here");  //Replace table name here

gr.get("SYS_ID_OF_RECORD"); //Replace with sys_id of your record

gr.field_name = "value";  //Replace with field name and required value in here

gr.setWorkflow(false);

gr.update();

 

AbdulAzeez
Mega Guru

 

Navigate to Background Scripts:

 

var inc  = new GlideRecord('incident'); // Give the table name
inc.get('SYSID OF the Record you want to change');
inc.short_description = "Give the value you want to Change"; // Give the Field name
inc.setWorkflow(false);
inc.update();

 

Regards,

Abdul Azeez

Mark Helpful / Correct based on the impact