How to temporarily disable Calculated field logic when updating via script or data patch?

Risinkou1
Tera Contributor

Hi,

I have a question regarding updating a field that has the "Calculated" option enabled in a custom table.

■ Background:
I want to update the value of this calculated field using a data patch or script.
My goal is to temporarily disable the calculation logic, set the value manually, and then re-enable the calculation.

■ Questions:
1. Is there a way to temporarily disable the Calculation flag during script execution?
2. Can I use `GlideRecord.setWorkflow(false)` or similar methods to skip calculation scripts during updates?
3. Are there recommended best practices for this kind of override/update of calculated fields?

Any guidance would be appreciated. Thanks!

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Risinkou1 

you cannot disable it temporarily. the calculation logic is at dictionary level.

setWorkflow() won't help as it's for avoiding business rule and not field level calculation

Workaround

1) Disable that calculated checkbox for your field

2) run your script

3) enable that calculated checkbox again

Going forward if same situation arises, then add the logic to calculate that field in before business rule and don't make that field as calculated

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@Risinkou1 

you cannot disable it temporarily. the calculation logic is at dictionary level.

setWorkflow() won't help as it's for avoiding business rule and not field level calculation

Workaround

1) Disable that calculated checkbox for your field

2) run your script

3) enable that calculated checkbox again

Going forward if same situation arises, then add the logic to calculate that field in before business rule and don't make that field as calculated

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader