- 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:27 AM
Let me explain
This is the list collector values
and now these are the roles in the drop down
As you can see the drop down has two choices, the first choice is in list collector but the second is not, now the problem is when even select the value which is not in list collector it still pops up.
Does that make sense? If not please let me know and I will upload a video showing what exactly its doing.
Thank You.
- 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:45 AM
I am now feeling embarrassed, I am sorry it still wont display any alerts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:25 AM
Hi Nasir,
I believe that this onChange Catalog Client Script is on role field. Can you try the following script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var gr = g_form.getValue('employee_current_roles'); // getting the List Collector Variable value
var ar = gr.split(','); // split the list collector by comma
if (ar.indexOf(newValue) >= 0) //if field values are the same then send alert
{
alert('User is already Member of the Selected role');
g_form.clearValue('role');
}
}
You can also try with a javascript array method which is array.includes.
Hopefully, this will resolve your query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2022 06:35 AM
Hi Muhammad,
Thank you, that's correct I have onChange Catalog Client script on role field, I tried what you mentioned and unfortunately it does not pop up at all, even tried
if (ar.indexOf(newValue) > -1)
This won't work too :(. I can do a look up of both the fields in flow designer and stop the flow from executing to next approval stage, but honestly its annoying and I know users will call back asking for the same thing to show reminder on the portal.