- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 11:29 PM
Hi ,
Need to know more about setForceUpdate method in glideRecord ?
Please help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 11:31 PM
Hi @Shubham Rai ,
‘setForceUpdate’ is used to update records without having to change a value on that record to get the update to execute. ‘setForceUpdate’ is particularly useful in situations where you need to force the recalculation of a calculated field for all records in a table or when you need to run business rules against all records in a table but don’t want to have to change a value on the records.This method is often used with ‘setWorkflow’ and ‘autoSysFields’ as shown below.
//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();
}
Please mark ✅ Correct if this resolves your issue, and also mark 👍 Helpful if you find my response valuable based on its impact.
Regards,
Astik Thombare
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 11:31 PM
Hi @Shubham Rai ,
‘setForceUpdate’ is used to update records without having to change a value on that record to get the update to execute. ‘setForceUpdate’ is particularly useful in situations where you need to force the recalculation of a calculated field for all records in a table or when you need to run business rules against all records in a table but don’t want to have to change a value on the records.This method is often used with ‘setWorkflow’ and ‘autoSysFields’ as shown below.
//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();
}
Please mark ✅ Correct if this resolves your issue, and also mark 👍 Helpful if you find my response valuable based on its impact.
Regards,
Astik Thombare

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2023 11:35 PM
Hi @Shubham Rai ,
The setForceUpdate
method in ServiceNow is used to update records without having to change a value on that record to get the update to execute. This method is particularly useful in situations where you need to force the recalculation of a field or perform a mass update of records without changing their values
Here's a sample code snippet demonstrating the use of setForceUpdate
:
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();
while (gr.next()) {
gr.category = 'hardware';
gr.setForceUpdate(true);
gr.update();
}
In this example, the script updates the category
field of all incident
records with a category
of 'software' to 'hardware' without changing any other values on the records. The setForceUpdate
method ensures that the update is executed even though no fields have been changed.