- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:31 AM
Good morning everyone,
I have created a Catalog Client Script and an Include Script so that a user that contains the keyword "Manager" in its firstname and/or lastname cannot be selected in a variable of type reference and displays a message in case an attempt is made to select .
The fact is that it is not executed correctly and I cannot find the error, I would appreciate your help, greetings
* Catalog Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var requestedFor = g_form.getValue('for_whom_are_you_requesting_this_item');
var ga = new GlideAjax('ALOCatalogItemOtherSoftwareAJAX');
ga.addParam('sysparm_name', 'isManager');
ga.addParam('sysparm_user', requestedFor);
ga.getXML(checkManager);
}
function checkManager(response) {
var isManager = response.responseXML.documentElement.getAttribute("answer");
if (isManager == 'true') {
g_form.showFieldMsg('for_whom_are_you_requesting_this_item', 'The user is not allowed.', 'error');
} else {
g_form.clearFieldMsg('for_whom_are_you_requesting_this_item');
}
}
* Script Include:
var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = {
isManager: function(userSysId) {
var gr = new GlideRecord('sys_user');
if (gr.get(userSysId)) {
return (gr.getValue('firstname').toLowerCase().indexOf('manager') !== -1 ||
gr.getValue('lastname').toLowerCase().indexOf('manager') !== -1);
}
return false;
},
type: 'ALOCatalogItemOtherSoftwareAJAX'
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:41 AM
Hi @Tomas Linde
It looks like your script include is not set as client callable. Make sure you check it client callable and also make sure the script extends the AbstractAjaxProcessor. The first part of you script include should look like this
var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:44 AM - edited ‎02-22-2024 03:44 AM
Hi @Tomas Linde ,
As i can see inside function isManger you are not passing the sysid of user, try adding below code
var userSysId = this.parameter ('sysparm_user');
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 04:33 AM
Hi @Tomas Linde, I have identified the issue with the field names of first_name and last_name in the script include.
var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isManager: function() {
var userSysId = this.getParameter('sysparm_user');
var gr = new GlideRecord('sys_user');
if (gr.get(userSysId)) {
return (gr.getValue('first_name').toLowerCase().indexOf('manager') !== -1 ||
gr.getValue('last_name').toLowerCase().indexOf('manager') !== -1);
}
return false;
},
type: 'ALOCatalogItemOtherSoftwareAJAX'
});
Also, you try the client script as below:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var ga = new GlideAjax('ALOCatalogItemOtherSoftwareAJAX');
ga.addParam('sysparm_name', 'isManager');
ga.addParam('sysparm_user', newValue);
ga.getXML(checkManager);
}
function checkManager(response) {
var isManager = response.responseXML.documentElement.getAttribute("answer");
if (isManager) {
g_form.showFieldMsg('for_whom_are_you_requesting_this_item', 'The user is not allowed.', 'error');
} else {
g_form.clearFieldMsg('for_whom_are_you_requesting_this_item');
}
}
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:41 AM
Hi @Tomas Linde
It looks like your script include is not set as client callable. Make sure you check it client callable and also make sure the script extends the AbstractAjaxProcessor. The first part of you script include should look like this
var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 03:44 AM - edited ‎02-22-2024 03:44 AM
Hi @Tomas Linde ,
As i can see inside function isManger you are not passing the sysid of user, try adding below code
var userSysId = this.parameter ('sysparm_user');
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 04:00 AM
Hi @Tomas Linde, As you are calling the script include from the client script, you need to check the Client Callable checkbox. The first two line in your script should be
Also, you need to retrieve the 'sysparm_user' parameter in the script include using the this.getParameter as show in the below script.
Script Include:
var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isManager: function() {
var userSysId = this.getParameter('sysparm_user')
var gr = new GlideRecord('sys_user');
if (gr.get(userSysId)) {
return (gr.getValue('firstname').toLowerCase().indexOf('manager') !== -1 ||
gr.getValue('lastname').toLowerCase().indexOf('manager') !== -1);
}
return false;
},
type: 'ALOCatalogItemOtherSoftwareAJAX'
});
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2024 04:05 AM
Thank you very much for the help, it still doesn't work.