We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

if script - approval group script - workflow utah

levino
Giga Guru

Hi there

i currently have 5 ifscripts,   i have mentioned 2 as per below

 

was wondering if could replace all 5 ifscripts with one script in the approval group

 

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

 

if so please provide me with a example 

 

Thank You

Levino
//
// For example:
// var answer = [];
// answer.push('id1');
// answer.push('id2');

 

 

answer = ifScript();
function ifScript() {
    var request = current.variables.create_or_modify;
	var requestType = current.variables.modifications_required;
	var group = current.variables.existing_group_display_name;
	var ourUser = gs.getUser();
   ourUser = ourUser.getUserByID(current.opened_by);
    
   if (request == 'Modify' && requestType == 'Add' && group == 'AAD_PowerApps_MarketingROI_Prod' && !ourUser.isMemberOf('PowerApps Marketing')) {
    return 'yes'; // this takes the output to group approval activity
    }
    return 'no'; // this skips group approval activity and takes to next activity
}

answer = ifScript();
function ifScript() {
    var request = current.variables.create_or_modify;
	var requestType = current.variables.modifications_required;
	var group = current.variables.existing_group_display_name;
	var ourUser = gs.getUser();
   ourUser = ourUser.getUserByID(current.opened_by);
    
   if (request == 'Modify' && requestType == 'Add' && group == 'AAD_PowerApps_Future' && !ourUser.isMemberOf('PowerApps Future')) {
    return 'yes'; // this takes the output to group approval activity
    }
    return 'no'; // this skips group approval activity and takes to next activity
}

 

 

2 REPLIES 2

PPPanchal
Mega Sage

Hello @levino,

It seems like your !ourUser.isMemberOf('PowerApps Future') condition is different in the second if Script.So you can merge code like below:

 

answer = ifScript();
function ifScript() {
    var request = current.variables.create_or_modify;
	var requestType = current.variables.modifications_required;
	var group = current.variables.existing_group_display_name;
	var ourUser = gs.getUser();
   ourUser = ourUser.getUserByID(current.opened_by);
    
   if (request == 'Modify' && requestType == 'Add' && group == 'AAD_PowerApps_MarketingROI_Prod' && !ourUser.isMemberOf('PowerApps Marketing') && && !ourUser.isMemberOf('PowerApps Future')) {
    return 'yes'; // this takes the output to group approval activity
    }
    return 'no'; // this skips group approval activity and takes to next activity
}

    

 

  

Please mark correct/helpful if this helps you!
Thanks,
Pratiksha
ServiceNow Rising Start 2025

hi there

will the above work if the approval group is different and the evaluated condition is different?

 

Thanks

Levino