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

Abhinay Erra
Giga Sage

reference qualifiers are just used to filter the data you see based on some conditions. In your case, you will need an onLoad and onChange client script for this


Thanks



So you mean I need to do an onLoad that gets the value of the user variable (I presume g_form.getValue('name') and then does a full round trip back to the server to query the position table for an employee that matches the name variable user object and then manually adds all of the options to the select box just so that they show on load, when I have a reference qualifier specified to do just that - it just doesn't fire onLoad.



This doesn't make any sense...


Abhinay Erra
Giga Sage

I got you. I have misunderstood your requirement. So you want to filter the look up select box based on the name variable right?


Yes - and it works fine if I change the name (it is a lookup select box itself) and change it back it populates the position lookup select box but it won't do it onLoad (event though the name variable is set).