how can i skip the approval

Rama26
Tera Contributor

Hi all,

i have a requirement,

i have 1 group. if the user related to that group i need to skip the approval other wise i need to send the approval for requested manager?

1 ACCEPTED SOLUTION

Hi,

you didn't tell user variable is of what type?

Is group name correct?

Also the script I shared would work provided the user variable is reference to user table

You said you want to skip the approval when user is part of group then you should return no when that user is member

answer = ifScript();

function ifScript(){

	var isMember = gs.getUser().getUserByID(current.variables.user+'').isMemberOf('Software');
	
	if(isMember)
		return 'no'; // take this output to next activity
	else
		return 'yes'; // take this output to approval activity

}

OR

answer = preapprovalcheck();

function preapprovalcheck() {
	var user = current.variables.name;
	var grMem = new GlideRecord('sys_user_grmember');
	grMem.addQuery('user', user);
	grMem.addQuery('group.name', 'Software');
	grMem.query();
	if (grMem.next()) {
		return 'no';
	} else {
		return 'yes';
	}
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

is this for catalog item?

Which user is related to that group?

The user who submitted the request? OR any user reference variable you have in your catalog form

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

yes it's a catalog item, in form i have a field and it's reference field (sys_user). which user i selected in that field that user available in xyz group i need to skip approval

Hi,

you can use IF activity in workflow and check that

answer = ifScript();

function ifScript(){

	var isMember = gs.getUser().getUserByID(current.variables.variableName+'').isMemberOf('Group ABC');
	
	if(isMember)
		return 'no'; // take this output to next activity
	else
		return 'yes'; // take this output to approval activity

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

it's not work for me so i written below script(still approval trigger whether user related to group also)

answer = preapprovalcheck();

function preapprovalcheck() {

var user = current.variables.name;

var grMem = new GlideRecord('sys_user_grmember');
grMem.addQuery('sys_id', user);
grMem.addQuery('group.name', 'Software');
grMem.query();
if (grMem.next()) {

return 'yes';

} else {
return 'no';

}

}