Want to write a fix script for removing value of a particular field in a form

Sayan
Mega Contributor

I want to write a fix script for a list of records in a table. There is a field in my form that has a particular type of value. I want to remove that value and make it empty,

1 ACCEPTED SOLUTION

var tab = new GlideRecord('your_table');
tab.addEncodedQuery('Your_encoded_query_here');
tab.query();
while(tab.next()){
tab.your_field_name = '';
tab.setWorkflow(false); //helps in prevent running of BR's while updating
tab.autoSysFields(false);
tab.deleteRecord();
}

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

To add, you may want to add SetWorkflow(false) to your script when you are mass updating records with a background script. 

Note: Scripts - Background should be used very carefully and only in non-production environments. Free-form JavaScript can negatively impact data and system performance.

https://developer.servicenow.com/blog.do?p=/post/training-scriptsbg/

 

-Pradeep Sharma

Santosh_Ksagar
Mega Sage
Mega Sage

Hi Sayan,

When you will write the script to empty the field value make sure you take only limited number of records to run the script. I ma not sure how many reocrd you have with such values but I would recomment to limit 1000 records at a time. That works for me when I do such update.

Thanks
Santosh