Reference Qualifier onChange

Michael Gedzelm
Tera Contributor

Hi.  I am attempting to create an advanced reference qualifier that runs when another field changes (before saving) but have been unsuccessful, as it only seems to run onload, not onchange. For example (only an example, what I'm trying to do is more complex), let's say I have two reference fields: states of the country (i.e. Alaska, Arkansas, etc.) and counties of the state. When the user changes the state, the reference qualifier should run and show only the counties in the state I have chosen. But the reference qualifier only seems to run after a save (onload). As mentioned earlier, what I'm trying to do is far more complex than this example and I need to run javascript on the server each time a field is changed. The main issue is how do I get a reference qualifier to run onchange before a save. Thanks.

1 ACCEPTED SOLUTION

Yes it works for me

Ref qualifier: javascript:new FillServers().pickServers(current)

SI: Client callable checked

var FillServers = Class.create();
FillServers.prototype = Object.extendsObject(AbstractAjaxProcessor, {
pickServers:function(){
var servers = [];
var location = current.u_location.getValue();
var cls = current.u_server_class.getValue();
if(!location && !cls)
return;
gs.log('Returned null', 'prateek');
var ci = new GlideRecord('cmdb_ci');
ci.addEncodedQuery("sys_class_name="+cls+"^locationLIKE"+location);
ci.query();
while(ci.next()){
servers.push(ci.name.toString());
}
return 'nameIN'+ servers;
},
type: 'FillServers'
});

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

15 REPLIES 15

pethumdesilva
Tera Guru

Hello Michael,

 

Could you try following reference qualifier in counties,
javascript:'field_name_of_state_in_counties='+current.variables.variable_name_for_states.getDisplayValue();

 

Best regards,

Pethum

Hello Pethum.  As I indicated, I need to run some server code each time the state field changes, and it is currently only happening onload. I need it to run onchange before the save/reload.  So this solution will not work.  Thanks.

Prateek kumar
Mega Sage

Wouldn't an onChange client script in combination with GlideAjax do the job? 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Hi Prateek.   I tried this with the server side returning the json of the contents (value pairs) for the dropdown.  But when I then tried using g_form.addOption with this result, it would not work because you can't do addOption for reference fields.  Thanks.