Check if a user has a Software Allocation
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 02:44 AM
I have a catalogue item that should return if a user already has an account using the alm_entitlement_user table.
Using the Requested For variable type - I have a catalogue client script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var ga = new GlideAjax('user_allocation'); //name of script include//
ga.addParam('sysparm_name', hasAllocation); //hasAllocation is the name of the function in the script include//
ga.addParam('sysparm_userid', newValue);
ga.getXML(assignedTo);
function assignedTo(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer && answer == 'true') {
g_form.hideFieldMsg('requested_for');
g_form.showFieldMsg('requested_for', "This colleague already has an account", 'info');
} else {
g_form.hideFieldMsg('requested_for');
}
}}
The script include:
var user_allocation = Class.create();
user_allocation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
hasAllocation: function(){
var name = this.getParameter('sysparm_userid');
if (gs.nil(name)) {
return;
}
var userEnt = new GlideRecord('alm_entitlement_user');
userEnt.addQuery('licensed_by','9ed570d537a01000deeabfc8bcbe5d61');
userEnt.addQuery('assigned_to', name);
userEnt.query();
if (userEnt.get(user)) {
return 'true';
}
},
type: 'user_allocation'
});
I'm very much a beginner at JavaScript so any help would be much appreciated.
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2024 06:59 AM
Hi,
This is an issue with your Script include. You should always call the next() function before checking data. Otherwise you can use hasNext() function. Refer the updated script highlighted below
var userEnt = new GlideRecord('alm_entitlement_user');
userEnt.addQuery('licensed_by','9ed570d537a01000deeabfc8bcbe5d61');
userEnt.addQuery('assigned_to', name);
userEnt.query();
if (userEnt.hasNext()) { // Make sure this line is update in the script include
return 'true';
}
Thank you,
Palani
Palani