How to Update Filter condition Using fix Script on "Template Field" type Fields in Service now
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 11:51 AM - edited 09-08-2024 11:54 AM
Hi All,
There are a lot of templates in the template table. I need to update all the state values to "New" using a fix script.
Could you please help me how to archive this requirement.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 01:13 PM
Hi, You can try below code.I have added comments for easy understanding.
// Define the table name, assuming it's a custom table, update 'u_template' to the correct table name
var templateTable = 'u_template';
// Query the Template table where the state is 'Analyze'
var gr = new GlideRecord(templateTable);
gr.addQuery('state', 'Analyze');
gr.query();
// Loop through each record and update the state to 'New'
while (gr.next()) {
gr.setValue('state', 'New');
gr.update(); // Save the change
}
// Add some log information (optional)
gs.log('Fix script completed: Updated state from "Analyze" to "New" in the Template table');
Let me know, if this helps !
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 09:38 PM
@Sndeveloper Adm State is not a field on that table. It's just a filter on template field. Above script is not working.
Thank you for your response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-08-2024 10:38 PM
Hi @sekhar5311,
Could you provide more details and include additional screenshots?
Thanks,
Rohit Suryawanshi