Filter Functionality in Reference field

rohit_murli
Tera Contributor

Hello All,

We have a requirement where, on the catalog form, if the Line of Business field value is selected, the SVP/VP reference field should filter and display the relevant names based on the selected value, allowing the user to choose from the options.

Currently, we have written a script include that displays the group members of the selected Line of Business in the reference field. However, in the client script, we are using the setValue method, which sets all member names to the field instead of providing a filter option for user selection.

To achieve the functionality where users can select from a filtered list, what changes should we make to the following client script?

 

 

var ga = new GlideAjax('JobGroupMember');
ga.addParam('sysparm_name', "getMembers");
ga.addParam('sysparm_organization', line);
ga.getXMLAnswer(callback);

function callback(response) {
var answer = JSON.parse(response); {
g_form.setValue("svp", answer.join(','));
}
}
}

 

Any help will be appreciated. 
Thank you.

1 ACCEPTED SOLUTION

@rohit_murli 

is group name variable or organization variable a string type or a variable

if it's string holding group name then update your script include function as this

 getMembers: function(groupName) {
     var users = [];
     var members = new GlideRecordSecure('sys_user_grmember');
     members.addQuery('group.name', groupName);
     members.query();
     while (members.next()) {
         var mates = members.user.sys_id.toString();
         users.push(mates);
     }
     return 'sys_idIN' + users.toString();
 }
 },

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

13 REPLIES 13

@rohit_murli 

you didn't answer my question

is group name variable or organization variable a string type or a variable?

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar
organization field is a variable, type : Select Box. 

@rohit_murli 

you are using GlideRecorSecure so did you check the user with whom you are testing has read access to that sys_user_grmember table?

Did you try with GlideRecord?

Did you try with admin role with GlideRecordSecure?

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

I tried, GlideRecord but it didn't work. Same logs are printed filter data is not displayed in the reference variable. 
Also i didn't impersonate any one and check as i'm not able to see the results. 

@rohit_murli 

please share the choices configured for that variable

organization field is a variable, type : Select Box.

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