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

Thanks Prateek.  Unfortunately, it did not work.  Same thing.  Only executes on load, not on change.  Here's what i'm doing:

javascript:new FSIWorkOrderClientUtils().test1(current.state);

 

current.state is the state field from a custom table extended from task.  It has values like "Resolved", "Pending", "New".  I am not doing anything with the parameter on the server, only gs.info.

 

Thanks.

The form isn't saved to the DB so we might not have access to current object. Try and see if you can get it working using below:

new SI().test1(g_form.getValue('state'));


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

Same issue.  Does not execute on change, only on load.  Have you tested this?  Is this executing on change for you?  Because my coworker is also testing this in a separate instance and has the same result.  It only executes on load, not on change.  Thanks

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

Hi Prateek.  Sorry for the delay.  I took a few days off.  Just wanted to let you know that the issue is apparently that we did not have anything in the "Dependent Field" tab of our Dictionary.  By filling in a Dependent Field, SN knows to run the reference qualifier whenever the dependent field changes.  Without a Dependent Field, it only runs on load, which is what was happening to us.   Thanks for your help and thanks to my coworker for finding the issue.