Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Catalog Reference Qualifier Not Firing onLoad

eddy42
Tera Expert

I have two variables on a catalog item. 'name' and 'position'.   The idea is that position is populated with all of the positions a person holds within the organisation when the name of the person is selected.   This works absolutely fine using reference qualifier and variable attributes except for one vital detail:

When I load the form the name gets populated with a default value (gs.getUserID();) but the second variable (position) doesn't populate with anything.   If I change the name variable to something else and back again position populates fine - it's as if the position variable is referencing the name variable before it is populated.

I have scoured the forums and can find no-one else suffering this problem, but I can't see how variable attributes: ref_qual_elements=name is of any use to make a dependent field if it doesn't fire onLoad.

Help would be appreciated.

1 ACCEPTED SOLUTION

Well - I have a solution but it still seems to me to be a big flaw in the platform:



If I write a script include that does exactly the same things as my old reference qualifier (javascript:'u_employee='+current.variables.name):



Then add a clause to capture the occurance of 'name' being undefined (the onLoad) - it works fine (if a huge sledgehammer to crack a badly implemented event handler!):



function u_getPositionsForCurrentUser() {


     


      if (JSUtil.nil(current.variables.name)){


              user = gs.getUserID();                        


      }else{


              user = current.variables.name;


      }


     


      var answer = '';


      var grUser = new GlideRecord("sys_user");


      grUser.get("sys_id", user);


      var positions = new GlideRecord('u_ccc_position');


      positions.addQuery('u_employee', grUser.sys_id);


      positions.query();


      while (positions.next()) {


              if (answer!="") {


                      answer += ',' + positions.sys_id.toString();


              }


              else {


                      answer = positions.sys_id.toString();


              }


      }


      return 'sys_idIN' + answer;


}




and call it in the reference qualifier:   javascript:u_getPositionsForCurrentUser();


View solution in original post

6 REPLIES 6

Well - I have a solution but it still seems to me to be a big flaw in the platform:



If I write a script include that does exactly the same things as my old reference qualifier (javascript:'u_employee='+current.variables.name):



Then add a clause to capture the occurance of 'name' being undefined (the onLoad) - it works fine (if a huge sledgehammer to crack a badly implemented event handler!):



function u_getPositionsForCurrentUser() {


     


      if (JSUtil.nil(current.variables.name)){


              user = gs.getUserID();                        


      }else{


              user = current.variables.name;


      }


     


      var answer = '';


      var grUser = new GlideRecord("sys_user");


      grUser.get("sys_id", user);


      var positions = new GlideRecord('u_ccc_position');


      positions.addQuery('u_employee', grUser.sys_id);


      positions.query();


      while (positions.next()) {


              if (answer!="") {


                      answer += ',' + positions.sys_id.toString();


              }


              else {


                      answer = positions.sys_id.toString();


              }


      }


      return 'sys_idIN' + answer;


}




and call it in the reference qualifier:   javascript:u_getPositionsForCurrentUser();


eddy42


It works for me without the script include. I had the same setup as yours and using a default value. Onload, it populates the choices based on the value selected