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

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;


},




});


patricklatella
Mega Sage

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


   


}


patricklatella
Mega Sage

thanks Victor, got it working...did some other slight variations to get there but your direction helped a ton.


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!!


patricklatella
Mega Sage

will do...not seeing the button though, I'll look around