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

Prateek kumar
Mega Sage

You just need to return the sys_ids for the reference fields.

Share your script include script here, i'll see if i can help


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

Prateek, I'm not following you.  We are now talking about two different things:  a reference qualifier script vs. an onChange gladeAjax call.  These are entirely different things.  If an onChange glideAjax call returns sys_ids, what would I do with the sys ids when they are returned to my callback function in the onChange?  Of course, I could have the reference qualifier script return sys_ids, but as stated earlier, the reference qualifier script doesn't run onChange, only when the form loads.  Thanks.

My bad, misunderstood. Are you passing the dependant value in your reference qualifier condition?

javascript: new ScriptIncludeName().functionName('yourChangedValue');

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

No worries.  The answer to your latest question is no.  All I'm doing is testing to see when the server script executes with plans to put more stuff in later.  So I included no parameters:

javascript: new MySI().test1();

 

And on the server side, I have:

function test1()  {

gs.info("reached test1");

}

When I search the logs, I see that entries are only made onload not when I change the field.  Thanks.

pass in the parameter that you want this script to run on, eg: if states needs to show up pass in country value

new MySI().test(current.variable);


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