Business Rule to create approvers.

Anshika2
Kilo Expert

Hi, I am having one customization to create approvals through business rule. I have created a change request through catalog task. That change request is having one custom field u_group_approver. This field needs to be filled on the basis of change type i.e. standard, normal or emergency. 

1. If change type - Normal

u_group approval = Ateam

2. If change type - Normal

u_group approval = Bteam

3. If change type - Normal

u_group approval = Cteam

Now the approval should create for the assigned team members and if anyone would approve then it should create a change task and assigned to different teams based to database locations on catalog task form.

We cannot use workflow due to certain reasons. Can anyone help to do it with business rule.

 

4 REPLIES 4

Mahak2
Kilo Guru

Hello,

For 1st scenario:adding approvers

You can write "After Insert" BR rule on change_request table.

add the below script:

if(current.type=='standard')

{

current.u_group_approver = 'sys_id of Ateam';

current.update();

}

if(current.type=='Normal')

{

current.u_group_approver = 'sys_id of Bteam';

current.update();

}

if(current.type=='Emergency')

{

current.u_group_approver = 'sys_id of Cteam';

current.update();

}

 

Mahak2
Kilo Guru

Hello,

For 1st scenario:adding approvers

You can write "After Insert" BR rule on change_request table.

add the below script:

if(current.type=='standard')

{

current.u_group_approver = 'sys_id of Ateam';

current.update();

}

if(current.type=='Normal')

{

current.u_group_approver = 'sys_id of Bteam';

current.update();

}

if(current.type=='Emergency')

{

current.u_group_approver = 'sys_id of Cteam';

current.update();

}

 var gr = new GlideRecord('sysapproval_approver');

gr.initialize();

gr.approver= current.u_group_approver;

gr.sysapproval=current.sys_id;

gr.state='requested';

gr.insert();

 

 

For 2nd Scenario:

You can create an after update business rule on the Approval table.

Add below condition:

previous.state == 'requested' && current.state == 'approved';

var gr = new GlideRecord('sc_task');

gr.initialize();

gr.parent = current.request_item;

gr.short_description = 'QA Testing Task';

gr.request_item = current.request_item;

gr.insert();

Mark my response as Helpful and correct as applicable.

Thanks

Anshika2
Kilo Expert

Hi Mahak... Thank you so much for your help. I am able to generate the task now. But do you know how we can generate multiple change tasks and assign them to diff groups?

 

Hello,

Please use below script:

if(current.operation()=='insert')
      {
        var taskk=new GlideRecord('sc_task');
        for(var i=0;i<2;i++){
        taskk.initialize();
        taskk.caller_id=current.caller_id;

if(i == 0){
        taskk.assignment_group.setDisplayValue("ABC");

}

if(i ==1){

        taskk.assignment_group.setDisplayValue("DEF");

}
        taskk.insert();
        }
    }

Mark my response as Helpful and correct as applicable.

Thanks