Not equal to is not working in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-02-2023 07:51 PM
Hi,
I am trying to remove choice options from variable based on grade level is not management 18 and above. I tried using the below script and it is not working. Please help! Thanks,
function updateCampus(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
//if ((answer == 'Management 18') || (answer == 'Management 19') || (answer == 'Management 20') || (answer == 'Management 21') || (answer == 'Management 22')) {
if (answer != 'Management 18' || answer != 'Management 19' || answer != 'Management 20' || answer != 'Management 21' || answer != 'Management 22') {
g_form.removeOption('role_data_access', 'Leadership');
g_form.removeOption('role_data_access', 'Executive');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 04:20 PM
Hi,
Try using following
answer.indexOf("Management 18") == -1
OR
You may even use else part if equals to is working.
Mark it correct answer if this works for you.
Regards,
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 04:30 PM
It is not working,
There are more than 50+ values for equal to that is why i want to restrict based on not equal to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 07:04 PM
Have you tried with toString()

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 07:18 PM - edited ‎03-06-2023 07:20 PM
Hi,
I'd recommend going about this another way...you're already doing a query in your script include right? From the user sys_id you're passing to it from the GlideAjax call? Why not also add to the query that the management grade should not be Management 18 or Management 19 or Management 20, etc. You can build this query in list view for the relevant table, right-click the last piece of the filter breadcrumb and then use it as an addEncodedQuery("paste_query") to your script you have.
Example:
gr.addEncodedQuery("active=true^emailLIKE@example.com");
Then, if there's a result, return true if not, return false. As simple as that. Then, in your client script you just need to look for true or false and then remove the options depending on the relevant result. It's not really needed to do all that evaluation in the client script when you could handle it all in the script include.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2023 07:38 PM
I have added encoded query but its returning true for all records even though grade value is not management 18.
getGradeLevel: function() {
var sysid = this.getParameter('sysparm_sysid');
var query = 'u_gradeINManagement 18,Management 19,Management 20,Management 21,Management 22,Management 23' + sysid;
var loc = new GlideRecord('sys_user');
loc.addEncodedQuery(query);
//loc.addQuery('sys_id', sysid);
loc.query();
if (loc.next()) {
//return loc.u_grade;
// if ((loc.u_grade == 'Management 18') || (loc.u_grade == 'Management 19') || (loc.u_grade == 'Management 20') || (loc.u_grade == 'Management 21') || (loc.u_grade == 'Management 22')) {
return true;
} else {
return false;
}
// }
},
Thanks,