If requested for is a member of assignment group no need approval else approval needed

latha13
Tera Contributor

Hello All,

Catalog Item having 2 fields requested for and assignment group here  I want "If requested for is a member of assignment group no need to send approval else approval needed

If script in workflow

answer = ifScript();

function ifScript() {
var reqFor = current.variables.requested_for.toString() ; 
if(reqFor.isMemberOf(current.variables.assignment_group.toString())){
return 'yes'; //no approval
}
return 'no';//trigger for approval
}

Above code is not working shows error in script..

Thanks

1 ACCEPTED SOLUTION

Sourabh26
Giga Guru

Hi,

Update your code as below.

answer = ifScript();

function ifScript() {
	var userObj = gs.getUser();
	var reqFor = userObj.getUserByID(current.variables.requested_for);
    var grp = current.variables.assignment_group;
	workflow.info('User = '+reqFor+' Group = '+grp);
    if (reqFor.isMemberOf(grp)) {
		workflow.info('YES');
        return 'yes'; //no approval
    }
	workflow.info('NO');
    return 'no'; //trigger for approval
}

 

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

View solution in original post

8 REPLIES 8

shloke04
Kilo Patron

Hi,

You would need a combination of Script Include and the current workflow script which you have written as below to handle this:

1) Create a Script include and use the script as below:

var checkMember = Class.create();
checkMember.prototype = {
    initialize: function() {
    },
	
	validateMember : function(groupName,requestedFor){
		var gr = new GlideRecord('sys_user_grmember');
		gr.addQuery('group',groupName);
		gr.addQuery('user',requestedFor);
		gr.query();
		if(gr.next()){
			return true;
		}else{
			return false;
		}
		
		
	},

    type: 'checkMember'
};

Now in your IF Activity in workfow used below:

answer = ifScript();
function ifScript(){
	var check = new checkMember().validateMember(current.variables.assignment_group,current.variables.requested_for);
}

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

So in above script Is Request for is a member of Selected Group on Form it will return as True and you can connect the Yes line from IF Block activity, else if not a member then it will return false and you can connect the No line from workflow activity.

Screenshot below for both code for reference:

find_real_file.png

find_real_file.png

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

latha13
Tera Contributor

Hi,

Tried with above code not working..

Thanks

What was the issue which you were facing? Please make sure to also reply back with the issue you are facing to assist further.

Also, as a best practice by using a Script Include as instructed above, it would have given an ability to use the same function anywhere else when there is a similar requirement by just calling a single line of code as below and passing the correct parameter and not every time writing several lines of Glide Record all the time.

var check = new checkMember().validateMember(current.variables.assignment_group,current.variables.requested_for);

Ultimately it's up to you to decide which ever method you want to go with.

 

Regards,
Shloke

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

Regards,
Shloke