Can you update a gliderecord and ignore/override data policies?

howard8
Tera Contributor

Hi,

I would like to update a GlideRecord with a business rule but a data policy is intercepting the update because I am not populating a mandatory field.   The logic of the update is correct through, my question is: Can you update a glide record and ignore/override data policies? I have tried setWorkflow, autoSysFields and setForceUpdate (in the example below) but they don't override a data policy.

//Force an update to all User records without changing field values

var gr = new GlideRecord('sys_user');

gr.query();

while (gr.next()) {

    gr.setWorkflow(false); //Do not run business rules

    gr.autoSysFields(false); //Do not update system fields

    gr.setForceUpdate(true); //Force the update

    gr.update();

}

The instance I am working on had all of it's UI policies converted data policies but they were only designed with what the user can do, in mind. They are now preventing backend scripts from doing their job.   I know I could go and modify each other them as an option, but from a technical stand point, I'd really like to know if they can just be ignored somehow.

Anyone done this before?

1 ACCEPTED SOLUTION

Apologies for updating an old thread, but I recently discovered this is possible. Just add:



gr.setUseEngines(false);



to the query. It's rather cryptically described on the wiki as "Disable or enable the running of any engines (approval rules / assignment rules)", but it also makes the query ignore data policies.



It's probably a bit late for this to be of any use to the original poster, but if nothing else I'll probably need this again in a few months, forget how I did it, google it and end up here again...


View solution in original post

8 REPLIES 8

Mujtaba Amin Bh
Mega Guru

By default, data policies are applied to all GlideRecord operations. You can opt out of applying the data policy to:


  • Target records of web services
  • Import sets
  • Client-side UI policies

Therefore, I don't think it is possible.



However, if there are only few data policies you can temporarily deactivate the Data Policies which are creating the problem.



For more info see:Background Script - Update Table With Mandatory Fields



Regards,


Mujtaba Bhat


Apologies for updating an old thread, but I recently discovered this is possible. Just add:



gr.setUseEngines(false);



to the query. It's rather cryptically described on the wiki as "Disable or enable the running of any engines (approval rules / assignment rules)", but it also makes the query ignore data policies.



It's probably a bit late for this to be of any use to the original poster, but if nothing else I'll probably need this again in a few months, forget how I did it, google it and end up here again...


Glad I came across this. It just saved me a whole lot of time. We have a script that runs to check for on-hold time and resets the incident to in-progress if the on-hold time has elapsed. The problem is that we have made some fields required with a data policy since we implemented this script and have hundreds of incidents in a stuck state because the script couldn't set them back to in-progress.....!!! This was very helpful. 

gr.setUseEngines(false);

 

Is still working as of 09/10/24.

 

Save me a heap of time as I had a Data Policy that needed to be set on some change task fields so they weren't editable from list view when I realized that the two BR's that look after some logic and updated the fields I had just restricted could now no longer update the fields 😅

 

Added gr.setUseEngines(false); to the BR's and reenabled it once the BR had run with  gr.setUseEngines(true); and it now works a treat!