- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 12:13 PM
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,
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 01:44 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 12:31 PM
Hi Sayan,
You can write the script something like this :
// suppose field is short description which you want to make empty
var rec = new GlideRecord('incident');
rec.addNotNullQuery('short_description'); //to fliter out records which has the values.
rec.setLimit(1); //remove this limit after testing one record whether scripts working fine or not.
rec.query();
while (rec.next()) {
rec.short_description = '';
rec.setWorkflow(false);
rec.update();
}
Refer this link to know more about fix scripts in servicenow:
You can even use the above script in background script also.
Please mark this answer as correct and helpful it resolves the query and helpful alone if it lead you in right direction.
Thanks,
Mohit Kaushik
Mohit Kaushik
ServiceNow MVP (2023-2025)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 12:36 PM
Try below:
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.update();
}
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 01:41 PM
What if I have to delete the whole record itself then what should be the code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2020 01:44 PM
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