how to pass sys ids from script include to client script:

Sathwik1
Tera Expert

There is a variable on a caltalog item named "IP" which is a reference field....I am stucked at client script...can anyone please help me...

Script Include

var Firewall_IP = Class.create();
Firewall_IP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    PopulatIPsBasedonLoc: function() {
        var Loc = this.getParameter('sysparm_location');
        var gr = new GlideRecord('ip_address');
        gr.addQuery('location', Loc);
        gr.query();
        var answer = [];
        while (gr.next()) {
            answer.push(gr.sys_id.toString());
        }
		return 'sys_idIN' + answer;
    },
    type: 'Firewall_IP'
});

OnChange Client Script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue == 'IP') {
        var grLocation = g_form.getValue('source_location');
        var ga = new GlideAjax('Firewall_IP');
        ga.addParam('sysparm_name', 'PopulatIPsBasedonLoc');
        ga.addParam('sysparm_location', grLocation);
    }
    //Type appropriate comment here, and begin script below

}
19 REPLIES 19

@Kieran Anson  In my variable I need to show only those two sysids...

 

Ok, so that's not what you originally asked. Rather that setting the value in the variable you're wanting to filter the field to only show the sys_ids returned by the script include?

Yes Exactly @Kieran Anson 

in that case you'd do this in the reference qualifier of the variable, not in a script include.

find_real_file.png

Your script include will also need to be updated.

var Firewall_IP = Class.create();
Firewall_IP.prototype = Object.extendsObject(AbstractAjaxProcessor, {
	PopulatIPsBasedonLoc: function(location) {
		var gr = new GlideRecord('ip_address');
		gr.addQuery('location', location);
		gr.query();
		var answer = [];
		while (gr.next()) {
			answer.push(gr.sys_id.toString());
		}
		return 'sys_idIN' + answer;
	},
	type: 'Firewall_IP'
});

Yeah I was aware of that...

But if you see my client script..here my requirement is quite complex...

  • If my new value is IP then I need to filter based on the script include conditions...
  • if newValue is some other then I have filter based on another field value..
  • another field but on same table..

Due to this I didn't prefer reference qualifier...and used onchange client script and script include... 

In this way is there is possiblity to filter records? or need to follow only with reference qualifier? if so please help me how can I provide multiple conditions in reference qualifier?

@Kieran Anson @Ankur Bawiskar @Shivani Singh @Muhammad @Jaspal Singh