Error In Background Script - Data Policy Exception!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 02:21 AM
Hello All,
This is my Background Script :
var incste = new GlideRecord ('incident');
incste.addQuery('number','INC002796596');
incste.query();
gs.log(incste.getRowCount());
if(incste.next()){
incste.state=7;
incste.autoSysFields(false);
incste.setWorkflow(false);
incste.update();
}
Note: I need to run the script for around 10k incidents.
When is Run this Script, i'm getting the below error message:
Background message, type:error, message: Data Policy Exception: The following fields are read only: State
We have a Data Policy , When the State field of the Incident is Resolved or Closed, make the field Read Only.
So, when i'm executing the script i'm getting this error. So, is there a way to run the script without any error.
Or i should deactivate the data policy and run the script?
I guess that is not preferable! Can anyone suggest me a solution?
Thanks,
Prem
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 02:24 AM
Below thread should be helpful
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 02:26 AM
Hi Prem,
Data policy will get executed in this case.
what is the data policy condition?
you need to deactivate that data policy to run this
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2019 02:48 AM
Hi there, instead using data policy on State field , please write the Onload client script as below:
if(g_form.state =='Close' || g_form.state =='Resolve')
{
g_form.setReadOnly('state',true);
}
incase you want all the fields readonly user below code:
var fields = g_form.getEditableFields();
for (var x = 0; x < fields.length; x++) {
g_form.setReadOnly(fields[x], true);
}
Now remove the data policy and try updating record it won't give you any error.
If this resolves your query, please mark my comments as correct and helpful
.
Regards,
Ajay Chavan