How can I modify value in read only field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 04:16 AM
Hi,
I have one question. I have created Script Actions and in this scipt I need to modify value in field. But this field is change by Data policy (it has set Read only on "false").
If I print into the log value of this field from the script, then value is empty.
Is possible to change this value?
Thank you, so much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 06:11 AM
Hi Petr,
You would change the field value with a GlideRecord operation. Something like this:
Standard disclaimer: The following code is untested, requires review and potential modifications.
var rec = new GlideRecord('incident');
rec.addQuery('active', true);
rec.query();
while (rec.next()) {
// Do something
rec.update();
}
Because GlideRecord defaults to running as "system", it bypasses the security on the record and fields. Your script action (or almost any other server side script) can update the field even if it is read-only.
http://wiki.servicenow.com/index.php?title=Script_Actions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 06:50 AM
Thank you for your reply. My code looks like similarly as your example.
But in log is not any error, or warning and incident will not change.
updateIncident();
function updateIncident(){
var gr = new GlideRecord('incident');
gr.get(current.sys_id);
gr.setValue('incident_state', 9);
gr.setValue('assigned_to', 'NULL');
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 06:52 AM
Try this instead. Since assigned_to is a sys_id, and 'NULL' is a string (not a null value), you can set it to empty like this:
updateIncident();
function updateIncident(){
var gr = new GlideRecord('incident');
gr.get(current.sys_id);
gr.setValue('incident_state', 9);
gr.setValue('assigned_to', ''); // use empty quotes
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2017 07:19 AM