how do I use a reference qualifier to pull data from a record?

patricklatella
Mega Sage

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!

1 ACCEPTED SOLUTION

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;


View solution in original post

20 REPLIES 20

patricklatella
Mega Sage

thanks Victor so much for your help, but it's still not working.   My java skills are limited...so when you say to remove the model category, do you mean to remove that whole line of code?  


patricklatella
Mega Sage

ideally we are trying to use one script include, called u_Computer_Requests_Ajax to handle all the data retrieval from a record within this set of catalog items.   the script include as is looks like this:



var u_Computer_Requests_Ajax = Class.create();


u_Computer_Requests_Ajax.prototype = Object.extendsObject(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;
      }
     
});



can I just add some code to this to get this functionality we're looking for?


sure just add this function



assets: function(){


  var user = current.cur_user.sys_id;


  return 'assigned_to='+user;


},



And call it with the Advance Ref Qual like: javascript: u_Computer_Requests_Ajax().assets();



And use the client script on change of cur_user



var count = 0;


  var gr = new GlideRecord('cmdb_ci_computer');


  gr.addQuery('assigned_to',newValue);


  gr.query();


  while(gr.next()){


  count++;


  }


  if(count==1){


  g_form.setValue('u_computer',gr.sys_id);


  }else{


  g_form.setValue('u_computer','');


  }


patricklatella
Mega Sage

so does this look correct for the new script include after adding the function to the script include?



var u_Computer_Requests_Ajax = Class.create();


u_Computer_Requests_Ajax.prototype = Object.extendsObject(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;
      }


assets: function(){


  var user = current.cur_user.sys_id;


  return 'assigned_to='+user;


},



});


patricklatella
Mega Sage

so sorry, when you say,



sure just add this function



assets: function(){


  var user = current.cur_user.sys_id;


  return 'assigned_to='+user;


},



where do I add that code?