- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 04:38 AM
Hi,
Sorry it might be a noob question but I have catalog item that has a list collector (employee_current_roles) which auto-populates user's roles with all the roles user is member of, I have another variable (role) on the form that is reference field and users can pick up any roles and log the request.
What I want to do is If any of the roles in list collector matches the value in referenced field I want a pop up to say User is already member of the role but I am not sure if what I am doing is correct, please help.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var urole = g_form.getValue('role');
var gr = g_form.getValue('employee_current_roles'); // getting the List Collector Variable value
var ar = gr.split(','); // split the list collector by comma
for (var i = 0; i < ar.length; i++);
if (ar.indexOf(urole) == -1) //if field values are the same then send alert
{
alert('User is already Member of the Selected role');
g_form.clearValue('role');
}
}
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:32 AM
That's strange issue,
Can you try adding below alert to see what values those variables are storing:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var urole = g_form.getValue('role');
var gr = g_form.getValue('employee_current_roles'); // getting the List Collector Variable value
if (gr.indexOf(urole) > -1) //if field values are the same then send alert
{
alert("gr value :"+gr+" urole : "+urole);
alert('User is already Member of the Selected role');
}
}
with new alert you might understand the exact issue else show me the alert data you are getting so that I can help you further.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Community Rising Star 2022
Regards,
Abhijit
ServiceNow MVP

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:49 AM
@Nasir
Can you share screenshot of your script, the whole form.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2022 11:42 PM
@Nasir
With all due respect, all of them have suggested the same thing and by taking their precious time and tried to help you but you have marked the same response which was shared with you much later.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 02:24 AM
@aman
Apologies mate honestly I can see now what I did wrong there, please take it as a noob mistake and will keep your feedback in mind for next time when I am marking correct Answer. I wish ServiceNow had an option to mark more than one correct answer and mark everyone who replied as champions :).
Again apologies for the rookie mistake!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 04:46 AM
Hi Nasir,
Instead of writing a client script better you need to exclude the roles which are there in list collector.
Reference qualifier:
javascript: "sys_idNOT IN"+current.variables.variable_name; //list collector variable name
Hope it helps
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 05:03 AM
Good Idea but I am using the same variable set in other categories on the same form, and requirement is to display the role for other categories as we are using those roles for employment types