How to add particular users to list type field based on choice value selection in record producer?

Udhya
Kilo Contributor

Dear all,

I have a choice field called "Versions" with values "A" & "B" and list type field called "Dedicated Users"

When A is selected add users Abel tutor, Abraham & Anne to list type field "Dedicated Users"

When B is selected add any member of "Service Desk" group to "Dedicated Users" field

How can I achieve it?

Please help!

Thanks

1 ACCEPTED SOLUTION

palanikumar
Mega Sage

You can achieve it via reference qualifier. Since you cant write your logic in single line, you need to create a script include refer it in reference qualifier

First create Script include named UserDetails with below code:

var UserDetails = Class.create();
UserDetails.prototype = {
    initialize: function() {},
	
    getUserDetails: function(version) {
		if(version == "A"){
			// Return sys_id of Abel tutor, Abraham and Anne
			// Update this to get dynamic values based on requirement
			return "a8f98bb0eb32010045e1a5115206fe3a,a8f98bb0eb32010045e1a5115206fe3a";
		}
		else{
			var userList = [];
			var gr = new GlideRecord("sys_user_grmember");
			gr.addQuery("group.name","Service Desk");
			gr.query();
			while(gr.next()){
				userList.push(gr.group.sys_id.toString());
			}
			return userList.join(",");
		}

    },

    type: 'UserDetails'
};

Once it is done, add below line in Reference qualifier of Dedicated Users variable

Note: Assuming Dedicated Users is Reference of Lookup Select variable referring User Table

Update versions in below line with actual variable name

javascript:"sys_idIN" + (new UserDetails().getUserDetails(current.variables.versions))

Update Variable Attributes of Dedicated Users variable with following

Update versions in below line with actual variable name for Versions

ref_qual_elements=versions
Thank you,
Palani

View solution in original post

1 REPLY 1

palanikumar
Mega Sage

You can achieve it via reference qualifier. Since you cant write your logic in single line, you need to create a script include refer it in reference qualifier

First create Script include named UserDetails with below code:

var UserDetails = Class.create();
UserDetails.prototype = {
    initialize: function() {},
	
    getUserDetails: function(version) {
		if(version == "A"){
			// Return sys_id of Abel tutor, Abraham and Anne
			// Update this to get dynamic values based on requirement
			return "a8f98bb0eb32010045e1a5115206fe3a,a8f98bb0eb32010045e1a5115206fe3a";
		}
		else{
			var userList = [];
			var gr = new GlideRecord("sys_user_grmember");
			gr.addQuery("group.name","Service Desk");
			gr.query();
			while(gr.next()){
				userList.push(gr.group.sys_id.toString());
			}
			return userList.join(",");
		}

    },

    type: 'UserDetails'
};

Once it is done, add below line in Reference qualifier of Dedicated Users variable

Note: Assuming Dedicated Users is Reference of Lookup Select variable referring User Table

Update versions in below line with actual variable name

javascript:"sys_idIN" + (new UserDetails().getUserDetails(current.variables.versions))

Update Variable Attributes of Dedicated Users variable with following

Update versions in below line with actual variable name for Versions

ref_qual_elements=versions
Thank you,
Palani