- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 03:15 PM
I have a field on a record producer called "Affected User", that when the user name is entered I want a 2nd field to populate automatically with data from a field on that user's record. In this case specifically a field for "Asset", which is the user's computer. Secondly, if the user has more than 1 asset listed in their user record (i.e. they have more than 1 computer assigned to them), I want the 2nd field to populate with all the assets for that user so that the user can select an asset to designate for the record producer. The record producer is for identifying issues with a computer for example. thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2017 05:01 PM
ok this is what I think that you want to accomplish
If the field user name is filled then the field asset show the hardware assets assigned to that user,
To do that the field user name must be a reference to the table 'sys_user'
and the field Asset must be a reference to the table 'alm_hardware' and you can use the script for advance Ref Qual in this field like this
var user = current.variables.cur_user;
return 'assigned_to=' + user;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 10:19 AM
yes , and in your code i think you had a missing semicolon, should be like this
var u_Computer_Requests_Ajax = Class.create();
u_Computer_Requests_Ajax.prototype = (AbstractAjaxProcessor, {
getModelDetails: function() {
var retVal; // Return value
var modelType;
var usageProfile;
var premiumModel;
var catItem = this.getParameter('sysparm_catitem');
var itemRec = new GlideRecord('sc_cat_item');
// If we can read the record, check if the sys_ids match
if (itemRec.get(catItem)) {
modelType = itemRec.model.u_model_type;
usageProfile = itemRec.model.u_usage_profile;
gs.log(usageProfile);
premiumModel = itemRec.model.u_premium_model;
}
retVal = modelType + '|' + premiumModel + '|' + usageProfile;
return retVal;
}, //<----Missing
assets: function(){
var user = current.cur_user.sys_id;
return 'assigned_to='+user;
},
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 10:34 AM
ok great, and then for the catalog client script I made for this "Set Current Computer", is this correct? You had said I don't need model category, so what would the correct code look like?
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var count = 0;
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('assigned_to',newValue);
gr.addQuery('model_category','81feb9c137101000deeabfc8bcbe5dc4');//Computers
gr.query();
while(gr.next()){
count++;
}
if(count==1){
g_form.setValue('u_computer',gr.sys_id);
}else{
g_form.setValue('u_computer','');
}
//Autopopulates if is only one computer Assigned or Clear the field if there is more than one in case that the user changes
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 11:49 AM
thanks Victor, got it working...did some other slight variations to get there but your direction helped a ton.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 01:17 PM
Glad to be helpfull, if is not too much to ask, could you mark as correct in orther to other users can use this as a reference when they have similar problems
Thanks!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2017 01:56 PM
will do...not seeing the button though, I'll look around