Filter Reference Field based on Another Variable.

alexcharleswort
Tera Expert

Is there a way to do this? I have two fields; u_location (reference to cmn_location table) and u_supplies (reference to u_supply_list table).

On the u_supply_list table, I have a checkbox variable u_omaha and when checked I know that supply is only available in that region.

What I want to have happen is if u_location == 'omaha', don't filter u_supplies, show them all;

                                                                                                 

                                                                                                  else, if u_location != 'omaha' filter u_supplie by u_omaha == false, done show any supplies that are Omaha only.

Any idea how I might be able to accomplish this? I haven't been able to find much other than static filters when I've searched online.

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alex,



You have to define advance reference qualifier on u_suplies and the reference qualifier will be


javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup()



Script will be


Name : BackfillAssignmentGroup


Script :


var BackfillAssignmentGroup = Class.create();


BackfillAssignmentGroup.prototype = {


  initialize: function() {


  },



  BackfillAssignmentGroup:function() {


  var gp = ' ';


  var a = current.u_location.getDisplayValue(); //Here I am assuming u_location is the column name



  //return everything if the location value is empty or location is omaha


  if(!a || a == 'omaha')


  return;



  var gr = new GlideRecord('u_supply_list');


  gr.addQuery('u_omaha',false);


  gr.query();


  while(gr.next()) {


  if (gp.length > 0) {


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


  }


  else {


  gp = gr.sys_id;


  }


  }


  return 'sys_idIN' + gp;


  },


  type: 'BackfillAssignmentGroup'


}




P.S : Here I am assuming you are not defining the reference qualifier on service catalog variables. Also please define the naming conventions as per your req.



Please let me know if you have any questions.


View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hi Alex,



You have to define advance reference qualifier on u_suplies and the reference qualifier will be


javascript:new BackfillAssignmentGroup().BackfillAssignmentGroup()



Script will be


Name : BackfillAssignmentGroup


Script :


var BackfillAssignmentGroup = Class.create();


BackfillAssignmentGroup.prototype = {


  initialize: function() {


  },



  BackfillAssignmentGroup:function() {


  var gp = ' ';


  var a = current.u_location.getDisplayValue(); //Here I am assuming u_location is the column name



  //return everything if the location value is empty or location is omaha


  if(!a || a == 'omaha')


  return;



  var gr = new GlideRecord('u_supply_list');


  gr.addQuery('u_omaha',false);


  gr.query();


  while(gr.next()) {


  if (gp.length > 0) {


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


  }


  else {


  gp = gr.sys_id;


  }


  }


  return 'sys_idIN' + gp;


  },


  type: 'BackfillAssignmentGroup'


}




P.S : Here I am assuming you are not defining the reference qualifier on service catalog variables. Also please define the naming conventions as per your req.



Please let me know if you have any questions.


Thanks, Pradeep! Nailed it again!



Question though, I want to make sure I understand...



var gr = new GlideRecord('u_supply_list');  


gr.addQuery('u_omaha',false);  


gr.query();  


while(gr.next()) {  


if (gp.length > 0) {  


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


}  


else {  


gp = gr.sys_id;  


}  


}  


return 'sys_idIN' + gp;


},  


type: 'BackfillAssignmentGroup'  


}



What do the bold/underlined bits mean?


Hi Alex,



Thanks for the update. Here is my comment.


if (gp.length > 0) {   //build a comma separated string of supplies if there is more than one


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


}



return 'sys_idIN' + gp;


// return supplies 


Hello.. I'm sorry, but can i get help with this question please? https://community.servicenow.com/community?id=community_question&sys_id=68514370db66db002be0a851ca961914

Hello.. I'm sorry, but can i get help with this question please? https://community.servicenow.com/community?id=community_question&sys_id=68514370db66db002be0a851ca961914