Attached SLA through fix script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 02:56 AM
Hi All,
We have requirement to attached the SLA for the existing record and set the has breached flag depending upon the created and actual start date difference.
If difference > sla duration then has breached we need to set to true else false.
In the script we are updating the run sla flag in sc_task which will attached the SLA and in the same script we are adding the logic to set has breached and updating in the task_sla.
However, its not updating the has breached flag on the task_sla first time when we are running the script.
If we run the script for the second time then its updating.
Is there any reason why its happening or do we have any method to pause after first update on sc_task.
Please check the below code snippet and kindly assist.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 03:46 AM
This could be beacuse you will have multiple SLAs associated with a single task, you can better, point to the specific SLA which you are looking to update, you can add query like, resolution SLA, state is one of in progress or complete.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2023 07:03 AM
Hi Aman,
I have single SLA attached to the task.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2023 11:28 PM
-
Ensure that the code to update the has_breached field on the task_sla table is executed after the update on the task sla table. Make sure there are no other scripts or business rules that might interfere with the order of operations.
-
By default, the update() function in ServiceNow is synchronous, meaning it waits for the update to complete before proceeding. However, you have commented out the line grTask.setWorkflow(false)that could have potentially disabled synchronous updates. Remove the comment and try executing the script again to ensure that the update on sc_task completes before moving to the task_sla update.
-
Check if there are any other asynchronous processes or scheduled jobs that might be running concurrently. It's possible that the task_slarecord is not yet available for update when the script runs for the first time, resulting in the update being successful on subsequent executions.
Aman Kumar