logo

NJP

Creating SLA/OLA definition automatically by business rule using script

Import · Aug 03, 2018 · article

It may happen that you would like to create any SLA or OLA automatically when, let's say any group is created (to automate the process of Service Level Mgmt definition).

For doing a case above, there might be useful to create a business rule on the sys_user_group table with the glide query on the contract_sla table.

Specification:

When: After

Insert: True

Advanced: True

In such a scripted business rule the most important is how to appropriately refer to S tart conditions. Namely, it requires providing the string "collection=table_name".

Exemplary code may look like :

(function executeRule(current, previous /*null when async*/) {

    var ola = new GlideRecord('contract_sla');


     ola.initialize();
     ola.name = "P1 " + current.name + " for all incs with Priority = 1"; //is setting contract name
     ola.target = 'Resolution';
     ola.setValue('start_condition','priority=1^assignment_group=Service Desk^EQ^collection=incident'); //is setting OLA conditions
     ola.type = 'OLA';
     ola.setValue('duration',gs.getDurationDate('0 1:0:0'));  //is setting OLA duration
     ola.schedule = '8-5 weekdays'; //OLA schedule
     ola.insert();

Then, once you create a new group, it will automatically create a new OLA definition like this:

image

View original source

https://www.servicenow.com/community/developer-articles/creating-sla-ola-definition-automatically-by-business-rule-using/ta-p/2330335