How create an SLA using script?

Pavan B V1
Tera Contributor

Hello Everyone, 

 

Hope you are doing well.

 

I am working on one integration. I am not very strong at scripting. I have a requirement to create SLA's based on the response we receive from a third party application. First my goal is to create SLA using scripting. Now i am able to create SLA in servicenow but not getting how to add start condition, pause condition, cancel conditions using script. Below is the code i have written. Kindly help me with the extension of the script by adding the condition in script.

Thanks in advance..

 

var slaRecord = new GlideRecord('contract_sla');
slaRecord .initialize();
slaRecord.name = 'Test Automated SLA 7';
slaRecord.type = 'SLA';
slaRecord.target = 'resolution';
slaRecord.collection.setDisplayValue('incident');
slaRecord.active = true;
slaRecord.duration_type.setDisplayValue('3 business days by 4pm'); -- Not being able to bring user specified duration, if you can help on this would also be very helpful.
//slaRecord.duration= new GlideDuration('1 12:00:00');
slaRecord.relative_duration_works_on = 'SLA record';
slaRecord.schedule_source = 'no_schedule';
slaRecord.insert();
 
Regards,
Pavan B V
2 REPLIES 2

Uncle Rob
Kilo Patron

Why do you want to create an SLA DEFINITION via script!?

So I am interested in automating the creation of SLA Definitions. We have several customers that have unique response /resolve SLAs, so I would like to have a catalog item that allows for creating SLAs based on a few variables like priority, schedule. based on these values, I would like to create SLA Definition records using a flow. my issue is that I am not very good with scripting in flow designer, and there is no way (that I can figure out) to populate the start, stop, pause, reset conditions. If you could give me some tips on how to populate the start, stop, pause, reset conditions(alond with the rest of the data to create an SLA Defintion record) from a flow it would be appreciated.