Error In Background Script - Data Policy Exception!

jaisankar
Mega Contributor

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
3 REPLIES 3

VigneshMC
Mega Sage

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Chavan AP
Kilo Sage

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 correctfind_real_file.png  and helpful find_real_file.png .

Regards,

Ajay Chavan

My Community Articles

LinkedIn

 

 

 

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****