Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Update Filter condition Using fix Script on "Template Field" type Fields in Service now

sekhar5311
Tera Contributor

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

template.PNG

3 REPLIES 3

Sndeveloper Adm
Tera Guru

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 

@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.

Hi @sekhar5311,
Could you provide more details and include additional screenshots?

Thanks,
Rohit Suryawanshi