- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-28-2018 09:23 AM
I created an SLA that must obtain results for "task_sla" records that have been created before the creation of the SLA. Therefore, I created a background script that fills in most of the fields from the task_sla record. However, I want to fill in the duration fields but I find it quite difficult. Also, I wasn't able to change the stage field from "In progress" to "Complete", because I believe there are some security rules that overpower a background script (I still have my doubts though).
var readonly = true;
var tsk = new GlideRecord('sc_task');
tsk.addQuery('short_description', "Please confirm the requestor proposal.");
tsk.query();
while(tsk.next()){
var gr = new GlideRecord('contract_sla');
gr.addQuery('name','RFS - Prepare Proposal');
gr.query();
if (gr.next()){
var tsla = new GlideRecord('task_sla');
tsla.addQuery('task', tsk.request_item);
tsla.addQuery('sla', gr.sys_id);
tsla.query();
if(tsla.next()){
gs.print("task number:" +tsk.request_item.getDisplayValue() + " RITM # in TASK SLA " + tsla.task.getDisplayValue() + " found, then skip creation.");
}else{
tsla.initialize();
tsla.sla = gr.sys_id;
tsla.task = tsk.request_item;
tsla.start_time = tsk.sys_created_on;
tsla.end_time = tsk.closed_at;
if(readonly){
gs.print(tsla.sla + ";" + tsla.task.getDisplayValue() + ";" + tsla.start_time + ";" + tsla.end_time);
}else{
tsla.insert();
}
}
}
}
Below is a screenshot that shows the fields I want to fill.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2018 12:42 PM
Oh, those fields. The 'Actual Elapsed Time' is calculated 24x7, no matter what. The 'Business Elapsed Time' is calculated based off the predefined schedule that you have attached to that SLA. To update them, they're expecting 'GlideDuration' values.
In your sub-production environment, create a record with an SLA you are willing to modify. Then copy the sys_id of the SLA record that's attached and use the following script to see how the numbers can be modified/manipulated:
var tSla = new GlideRecord('task_sla');
tSla.addQuery('sys_id', '<sys_id_goes_here>');
tSla.query();
if (tSla.next()) {
// 3 days, 11hr:11m:11s, you don't have to include days if you just want to change time.
tSla.business_duration = new GlideDuration('3 11:11:11');
tSla.update();
}
If this answers your question, please mark this as correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2018 12:42 PM
Oh, those fields. The 'Actual Elapsed Time' is calculated 24x7, no matter what. The 'Business Elapsed Time' is calculated based off the predefined schedule that you have attached to that SLA. To update them, they're expecting 'GlideDuration' values.
In your sub-production environment, create a record with an SLA you are willing to modify. Then copy the sys_id of the SLA record that's attached and use the following script to see how the numbers can be modified/manipulated:
var tSla = new GlideRecord('task_sla');
tSla.addQuery('sys_id', '<sys_id_goes_here>');
tSla.query();
if (tSla.next()) {
// 3 days, 11hr:11m:11s, you don't have to include days if you just want to change time.
tSla.business_duration = new GlideDuration('3 11:11:11');
tSla.update();
}
If this answers your question, please mark this as correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 04:54 PM
Is this script a background script?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2018 04:14 PM
I wrote this in a background script, yeah. I just wrote it there for demonstrative purposes. You can apply the logic and use dynamic values where you see fit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-30-2018 04:54 PM
Is this script a background script?