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

Try below

answer = preapprovalcheck();

function preapprovalcheck() {

var user = current.variables.name;

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

return 'yes';

} else {
return 'no';

}

}

using this script i am still getting approvals.

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