how to get list of all assets in a catalog variable

niharikayb
Kilo Contributor

Hi ,

I have a catalog item where we have 2 variables

requested for (reference field of user table)

serial number (reference field of asset table)

Based on the selection of 'requested for', i need to get all the assets assigned to him/her in the lookup field of 'serial number'

Please help me out.

Thanks in Advance

1 ACCEPTED SOLUTION

tanumoy
Tera Guru

Script Include:


Name: getAssignedTo


Client Callable: False


Code:



var getAssignedTo = Class.create();


getAssignedTo.prototype = {


  initialize: function() {


  },




  assigned:function() {


  var gp = ' ';


  var a = current.variables.requested_for;



  if(!a)


  return;



  var grp = new GlideRecord('alm_hardware');


  grp.addQuery('assigned_to', a);


  grp.query();


  while(grp.next()) {



  if (gp.length > 0) {


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


  }


  else {


  gp = grp.sys_id;


  }


  }


 


  return 'sys_idIN' + gp;


  },



  }




Advance reference qualifier: javascript:new getAssignedTo().assigned()




Note: Please provide the correct variable names and table names.


View solution in original post

12 REPLIES 12

I would think you could make it even simpiler from what i am seeing.



For your reference qualifier on the asset lookup Try:


javascript: 'assigned_to=' + current.variables.<requested for variable's name>


Hi Jacob,



thanks for your reply



It is still not working


tanumoy
Tera Guru

Script Include:


Name: getAssignedTo


Client Callable: False


Code:



var getAssignedTo = Class.create();


getAssignedTo.prototype = {


  initialize: function() {


  },




  assigned:function() {


  var gp = ' ';


  var a = current.variables.requested_for;



  if(!a)


  return;



  var grp = new GlideRecord('alm_hardware');


  grp.addQuery('assigned_to', a);


  grp.query();


  while(grp.next()) {



  if (gp.length > 0) {


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


  }


  else {


  gp = grp.sys_id;


  }


  }


 


  return 'sys_idIN' + gp;


  },



  }




Advance reference qualifier: javascript:new getAssignedTo().assigned()




Note: Please provide the correct variable names and table names.


Hi Paul,



Tried your code also.It is still not working


Could you please post what you have written with the screenshot of the configure variables.