Trigger Approval

Community Alums
Not applicable

Hello Team,

 

I have one requirement on Change _ request table:- 

when the user click on request for approval button , check approval affected CIs/services and condition are if approval group is Available trigger approval for approval group , if approval group is not available then check Owned By if owned by is  present it trigger to owned by if owned by is null then go or next condition managed by group if managed by group is available then it trigger to mangled by  and Managed by group is null then trigger approval to Managed by , we need achieve this functionality only flow designer , how we can activities functionality. 

 

I created for version 2 of change workflow   here in Approval Group activity  in workflow added code below:-

 

answer = [];
var a = current.sys_id;
var gr = new GlideRecord('task_ci');
gr.addEncodedQuery('task=' + a);
gr.query();
while (gr.next()) {
var ap = gr.ci_item.change_control;
var owned=gr.ci_item.owned_by;
var mana=gr.ci_item.managed_by; //.getDisplayValue()

if(ap!=null)
{
answer.push(ap);
}
else if (owned!=null)
{
answer.push(owned);
}
else
{
answer.push(mana);
}
}

 

Now i  am able  to trigger approval approval group , however not able to trigger for the owned by and managed by as per mentioned above condition. 

 

Note :- needs to e trigger approval to approval first then if it is null then needs to be trigger owned by , if again owned by is null needs to be triggered to managed by . please help me in above code to resolve this issue 

 

Thank you. 

4 REPLIES 4

Chetan Mahajan
Kilo Sage
Kilo Sage

Hello @Community Alums 

                          Try below logic modified your script based on condition 

answer = [];
var a = current.sys_id;
var gr = new GlideRecord('task_ci');
gr.addEncodedQuery('task=' + a);
gr.query();

var approvalGroup = null;
var ownedBy = null;
var managedBy = null;

while (gr.next()) {
    var ap = gr.ci_item.change_control;
    var owned = gr.ci_item.owned_by;
    var mana = gr.ci_item.managed_by;

    if (ap != null && approvalGroup == null) {
        approvalGroup = ap;
    }
    
    if (approvalGroup == null && owned != null && ownedBy == null) {
        ownedBy = owned;
    }
    
    if (approvalGroup == null && ownedBy == null && mana != null && managedBy == null) {
        managedBy = mana;
    }
}

// Now trigger approvals based on the collected values
if (approvalGroup != null) {
    answer.push(approvalGroup);
}

if (approvalGroup == null && ownedBy != null) {
    answer.push(ownedBy);
}

if (approvalGroup == null && ownedBy == null && managedBy != null) {
    answer.push(managedBy);
}

// Now 'answer' array contains the values in the desired order to trigger approvals

Kindly mark correct and helpful if applicable

Community Alums
Not applicable

Hello Chetan,

 

It only triggering until the approval group , it is not triggering for owned by and managed by  under task_ci  table .

Please le me know where we wrong on this . same error after changing the code as well. Hv u tried in your instance this ?

 

Community Alums
Not applicable

Hello Chetan,

 

It only triggering until the approval group , it is not triggering for owned by and managed by  under task_ci  table .

Please le me know where we wrong on this . same error after changing the code as well. Hv u tried in your instance this ?

Hello @Community Alums ,

No I haven't tried it on my instance, Can you please share that error ?