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

victortrejo
Giga Expert

Hi Patrick, you can use an Advance RefQual like this


javascript: new scriptinclud().my_function();


to call a Script Include and use the 'current.variables.affected_user' to use the value of the field and do the script logic that you need


also i recommend a ui policy to display the second field when the first is populated



If this helps you please mark as correct or endorse, thanks!!


patricklatella
Mega Sage

thanks Victor,


so here's my script include so far...I'm assuming I have issues.   After further inspection I need the affected user (which is an entry from the user table) to trigger the 2nd field to populate with their assigned asset, however the actual connection is made from the CI record of the computer, which has an "assigned to" field...trying to determine how the code should look with this path.   again, my code below is not working, any help would be great.



AssetRefQual:function() { //Returns the reference qualifier for Assets assigned to Affected User


  var refqual ='';


  var systemType = current.variables.cur_user;


  if(systemType.indexOf("CI") = 1){ //System Type variable contains 1 entry


    refqual = 'u_type=Asset';


  }


  if(systemType.indexOf("CI") > 1){ //System Type variable contains more than 1 entry


    refqual += '^ORu_type=Asset';


  }


  refqual += '^ORu_type=All';


  //gs.log('refqual:' + refqual);


  return refqual;


},


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;


patricklatella
Mega Sage

yep, that's what I'm shooting for.   And further if the user name has only 1 computer assigned to it, then I want the 2nd field. which is called "Current Computer", "current_computer" to auto populate with that computer.   If the user name has more than 1 computer assigned to it, then I don't need the field to autopopulate, rather when you pull up the search list, the associated computer show there and they can pick the one they want.   Regarding the code, is the overall layout of my code above close to correct?