Script is not working for the approval

Mainkanta
Tera Contributor

Hello everyone,

Good day

 

I have the requirement to Tigger group approval based on the selection of the value on the look up select box variable.

example:

in the list collector i have 1,2,3,4,5 as the choices. I have the specifically approval for the choice 2. 

When i have tried my script it is working for the single choice i.e., if i select the only 2 while filling the form it is triggering the approval. If i select the 1,2,3 as the choices. the approvals are not triggering. 

 

Kindly help me with the script please.

 

This is the script i have created:

approvals();

function approvals() {
    var dbname = current.variables.database_name.getDisplayValue();
    gs.info("DBName vlaue" + dbname);

    var reqtype = current.variables.request_type;
    if (current.operation() == 'insert') {
        if (reqtype == 'add' || reqtype == 'grant_permission' || reqtype == 'revoke_permission') {

            var val = [];
            val = dbname.split(",");
            for (var i = 0; i < val.length; i++) {
                gs.info("Val array values " + val[i]);
            if (val[i] == 'DWPRD') {
                gs.info("Inside the if loop");
                var app = new GlideRecord('u_generic_approval');
                app.addQuery('u_other_approval_type', ' DWPRD');
                app.query();
                if (app.next()) {
                    var group = new GlideRecord('sys_user_group');
                    group.addQuery('sys_id', 'IN', app.u_group_approvers);
                    group.query();
                    while (group.next()) {
                        current.variables.workflow_group_approvers += group.name + '@' + group.sys_id + ';\n';
                    }
                }
            }
        }

    }
}
}
1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @Mainkanta ,

In the IF condition i guess you are checking for a single value.

 

May be try with this below code where i have used indexOf to search the option which might work for you.

 

   if (val.indexOf('DWPRD')>0) 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

View solution in original post

2 REPLIES 2

Mohith Devatte
Tera Sage
Tera Sage

Hello @Mainkanta ,

In the IF condition i guess you are checking for a single value.

 

May be try with this below code where i have used indexOf to search the option which might work for you.

 

   if (val.indexOf('DWPRD')>0) 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

Hello Mohith,

 

Thanks for the Quick response.

 

Thanks,

Manikanta