How to get all active assets assigned to the user in the variable of record producer.

Chiranjeevi K
Tera Expert

I have a requirement to get all the active assets assigned to the user in the variable (Lookup Select box) of record producer to achieve this used the script include and the reference qualifier in the variable as below but still the variable shows nothing while drop down for the list, please help with the solution.

 

Script Include: -
getAssignedDevices: function(typ) {
var req_for = current.variables.requested_for;
var devices = [];
var pc = new GlideRecord("cmdb_ci_pc_hardware");
pc.addQuery('assigned_to', req_for);
pc.query();
while (pc.next()) {
if (typ == "windows") {
if (pc.manufacturer != "b7e9e843c0a80169009a5a485bb2a2b5") { // not Apple
devices.push(pc.getValue('sys_id'));
}
} else if (typ == "mac") {
if (pc.manufacturer == "b7e9e843c0a80169009a5a485bb2a2b5") { //Apple
devices.push(pc.getValue('sys_id'));
}
}
}
return 'sys_idIN' + devices;
},

 

Reference Qualifier:- javascript:new AssetUtils().getAssignedDevices();

 

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

typ is going to be undefined as you did not include that in the reference qualifier.  I'm not sure if you have access to the current object, so best to pass in requested for as well. 

javascript:new AssetUtils().getAssignedDevices(current.variables.v_type,current.variables.requested_for);

Also ensure the Client callable box is checked on the Script Include.

Thanks for the response @Brad Bowman  I marked the script include as client callable and also defined the reference qualifier as your suggested but still it is not showing the list of active devices assigned to the user, could you please help me with the other ways if possible.

Is there a particular reason you are using a lookup select box type variable for this?  Reference variables are much more robust and easier to work with.  I mocked this up in my PDI and was having trouble getting the Lookup Select Box reference qualifier to work.  I haven't used them much but know there are limitations on the qualifier, so I'm not sure if calling a Script Include works with these.  If you change the variable to Reference, the qualifier will work - given the variable names match yours.

I got this to work in my PDI with a Lookup Select Box.  The key to making it work is to add to the Variable attributes field on this variable

ref_qual_elements = v_type 

You should also be able to add a semicolon and a second variable so that whichever one is changed the list will be updated, but I couldn't get that to work for some reason.  Also make sure the Lookup label fields have an underscore when there's more than one word - model_id, asset_tag, assigned_to - or they will appear as null in the list.  The reference variable works fine without the attribute.