In a catalog form we have a Multi row variable set with multiple drop down values. I need to populate approval based upon the drop down values..

Sofiya Perumal
Tera Expert

Hi Experts,

In a catalog form we have a Multi row variable set with multiple drop down values. I need to populate approval based upon the drop down values. If we select scadaprd or scada dev it must go to sacada approval, if we select prod it must go to security approval. These 2 I have achieved in the script. If an user selects both the approval it must go to both scada and security approval. Could you please validate the script. (Refer the screenshot for the script)

answer = ifScript();

function ifScript() {
var result = '';
var mrvs = current.variables.domain1; 
gs.log("MRVS"+mrvs.toString());
var rowCount = mrvs.getRowCount();
for (var i = 0; i <= rowCount; i++) { //loop through each row of the MRVS
var row = mrvs.getRow(i);
if(row!=null){
if (row.do1=='scadaprd') { //your variable name and select box choice value'

return 'yes'; //follow the path for Flex team approval
    
}
else if(row.do1=='scada_dev')
{
    return 'yes';

    }
}
}
    gs.log("flow went to");
return 'no';
}

 

Thanks in Advance,

Regards,
Sofiya

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Sofiya Perumal 

My suggestion here will be to use a combination of Run Script and Approval Activity to trigger your approvals.

1. Use an Run Script activity before your Approval Activity block and use the script below in your Run Script activity as below:

var firstSeletced = false;
var SecondSeletced = false;
var mrvs = current.variables.domain1; 
var rowCount = mrvs.getRowCount();
for (var i = 0; i <= rowCount; i++) { //loop through each row of the MRVS
var row = mrvs.getRow(i);
if(row!=null){
if (row.do1=='scadaprd') { //your variable name and select box choice value'
workflow.scratchpad = 'scadaprd'; 
firstSeletced = true;   
}
else if(row.do1=='scada_dev'){
workflow.scratchpad = 'scada_dev';
SecondSeletced = true;  
}
else if(firstSeletced == true && SecondSeletced == true){
workflow.scratchpad = 'both';    
}
}
}

Now add a User/Group Approval Activity as you need and use the script below:

// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.

if (workflow.scratchpad == 'scadaprd') {
    answer.push('Your First Approval here');
} else if (workflow.scratchpad == 'scada_dev') {
    answer.push('Your Second Approval here');
} else if (workflow.scratchpad == 'both') {
    answer.push('Your First Approval here');
    answer.push('Your Second Approval here');
}

Alternatively, below is an article which also shows the steps to handle multiple condition within an IF block as well, please refer the same:

https://community.servicenow.com/community?id=community_article&sys_id=6a4043c7db9bfb4013b5fb24399619a6

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

3 REPLIES 3

Tudor
Tera Guru

Hello Sofiya,

From what I see you are trying to achieve this in a workflow.

If so, then I would suggest(if possible) to switch to an approval coordinator and add to approval user/group activities, which are conditioned something like(scripted condition) - it would be easier to do without the approval coordinator, but in the off chance there are users who are part of both groups you these can be approved seperately and you can trace that.

Hope this helps!

 Tudor

 

Anil Lande
Kilo Patron

Hi,

You are using If activity which can return only Yes or No.

Instead you can use same script in Group approval activity and you don't need to write multiple group activities. You can use only one to handle approvals.

You can use something like below:

var answer = [];
var result = [];
var mrvs = current.variables.domain1;
gs.log("MRVS" + mrvs.toString());
var rowCount = mrvs.getRowCount();
for (var i = 0; i <= rowCount; i++) { //loop through each row of the MRVS
    var row = mrvs.getRow(i);
    if (row != null) {
        result.push(row.do1.toString());
    }
}

if (result.indexOf('scadaprd') > 0 && result.indexOf('scada_dev') > 0) { // scadaprd or scada_dev is selected
    answer.push('add sys_id of group'); // sys_id of Scada Group	
}
if (result.indexOf('prod') > 0) {
    answer.push('add sys_id of group'); // sys_id of Security group
}

This would be optimized way to achieve same with only one activity,

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

shloke04
Kilo Patron

Hi @Sofiya Perumal 

My suggestion here will be to use a combination of Run Script and Approval Activity to trigger your approvals.

1. Use an Run Script activity before your Approval Activity block and use the script below in your Run Script activity as below:

var firstSeletced = false;
var SecondSeletced = false;
var mrvs = current.variables.domain1; 
var rowCount = mrvs.getRowCount();
for (var i = 0; i <= rowCount; i++) { //loop through each row of the MRVS
var row = mrvs.getRow(i);
if(row!=null){
if (row.do1=='scadaprd') { //your variable name and select box choice value'
workflow.scratchpad = 'scadaprd'; 
firstSeletced = true;   
}
else if(row.do1=='scada_dev'){
workflow.scratchpad = 'scada_dev';
SecondSeletced = true;  
}
else if(firstSeletced == true && SecondSeletced == true){
workflow.scratchpad = 'both';    
}
}
}

Now add a User/Group Approval Activity as you need and use the script below:

// Set the variable 'answer' to a comma-separated list of user ids and/or group ids or an array of user/group ids to add as approvers.

if (workflow.scratchpad == 'scadaprd') {
    answer.push('Your First Approval here');
} else if (workflow.scratchpad == 'scada_dev') {
    answer.push('Your Second Approval here');
} else if (workflow.scratchpad == 'both') {
    answer.push('Your First Approval here');
    answer.push('Your Second Approval here');
}

Alternatively, below is an article which also shows the steps to handle multiple condition within an IF block as well, please refer the same:

https://community.servicenow.com/community?id=community_article&sys_id=6a4043c7db9bfb4013b5fb24399619a6

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke