- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-15-2017 07:54 PM
Hi guys,
I have a Client script onLoad which removes an "approval" action from a drop down list when the logged in user is not part of a site's manager group. The script works perfectly fine when I add/remove myself from this group, however when I am adding users to that group the script is not working for them.
I read in the wiki that dot walking doesn't work in client scripts, however that doesn't explain why my alerts are printing the dot-walked fields correctly, nor why the code works when I add and remove myself from that manager group (I can't see why an admin role would change any of this code).
var person = g_user.userID;
var managerGroup = g_form.getDisplayBox('location').value + " - Site Managers";
var mr = new GlideRecord('sys_user_group');
mr.addQuery('name', managerGroup);
mr.query();
if(mr.next()){
var ir = new GlideRecord('sys_user_grmember');
ir.addQuery('group', mr.sys_id);
ir.addQuery('user', person);
ir.query();
alert("manager group: "+ mr.name + ", manager sys_id " + mr.sys_id);
if(ir.next()){
alert(g_user.getFullName() + " is in the group")
// Show all options if it's 'Pending Extension'
// Otherwise use the below logic to show/hide the options.
if (g_form.getValue('state') != -35 ){
// Only show Approve if the state is Pending Client Approval.
if (g_form.getValue('state') == -31 ){
g_form.removeOption('u_action', 'Extend');
g_form.removeOption('u_action', 'complete');
} else{
g_form.removeOption('u_action', 'approve');
}
}
} else {
alert(g_user.getFullName() + " is NOT in the group");
g_form.removeOption('u_action', 'approve');
}
} else {
alert("no site manager group found");
}
Can anyone please guide me to a different way to show/hide items in a choice list like this, or can you identify a fault in the above code that i'm missing?
Solved! Go to Solution.
- Labels:
-
Incident Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 07:29 PM
Hi Ahmad,
Can you please give a try to run the client script with getXML() instead of getXMLAnswer().
--------------Client script--------------
function onLoad() {
var loc= g_form.getReference('location', doAlert); // doAlert is our callback function
}
function doAlert(loc) { //reference is passed into callback as first arguments
var grp = loc.name;
var gax = new GlideAjax('AL_checkUserGroup');
gax.addParam('sysparm_name','isUserSiteManager');
gax.addParam('sysparm_location',grp);
gax.getXML(ajaxResponse);
function ajaxResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
if(answer == true) {
//code
else {
//more code
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 10:52 PM
Hi Srinivas,
I've replaced that line but it did not fix the issue, i've also placed a gs.log entry into the function which does not appear in my logs when I reload the form, so I have a feeling that I'm not actually calling the function correctly in the first place. Only problem with that is I've copied the helloWorld example in the glideAjax wiki and that "answer" that is being displayed in the alert is also null, please refer above to the sample code i'm trying to get working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 11:14 PM
Hi Ahmad,
Have you marked the script include as client callable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2017 05:48 PM
Hi Sneha,
Yep, I missed that client callable checkbox, the script is working now.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-16-2017 10:54 PM
Have you enabled Client Callable Checkbox on your script include?