Asset based on requester of catalog item

nortonxnorris
Giga Expert

I have the following script includes, and calling it on the Asset reference field on my catalog request form.

The goal is to pull the list of assets of the 'requested_for" user. Any idea why this script does not work?

function BackfillAsset() {

  var gp = "";

  var a = current.variables.requested_for;

  //return everything if the requested_for value is empty

  if(!a)

  return;

    var grp = new GlideRecord('alm_asset');

    grp.addQuery('assigned_to', a);

  grp.query();

  while(grp.next()) {

          if (gp == "") {

  gp = grp.sys_id;

}

    else{  

      //build a comma separated string if there is more than one

            gp = gp +','+grp.sys_id;

    }

  }

 

  var returnValue = "sys_idIN"+gp ;

  return returnValue;

}

1 ACCEPTED SOLUTION

I changed this back to a reference field and added the following:


Variable attributes: ref_qual_elements=current.variables.requested_for


Ref qual: javascript: 'assigned_to='+current.variables.requested_for



Worked fine!


View solution in original post

4 REPLIES 4

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Norton,



Please go through the below thread for reference.


Reference qualifier fails when a Reference type variable is changed to a Lookup Select Box


Hi Pradeep Sharma



I changed the variable type to lookup select box.


Lookup from table= alm_asset


Lookup field value: asset tab


Lookup field labels: asset_tag, display_name



Reference qualifier: javascript: BackfillAsset()



This brings up a list of all assets. What am I still missing?


I changed this back to a reference field and added the following:


Variable attributes: ref_qual_elements=current.variables.requested_for


Ref qual: javascript: 'assigned_to='+current.variables.requested_for



Worked fine!


Awesome work @nortonxnorris@gmail 

Was super helpful. I just dont like how its in a selection drop down, but I'm sure I can figure that out soon! (probably because its a reference list)

Have you done that?

If others are interested here's how it looks like (a picture is worth a million words :))

find_real_file.png