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
Kilo Patron

Hi,
Not sure what you want to do with the response but you can use getXML() and getXMLAnswer() to get the response from the script include:

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);
		ga.getXMLAnswer(function(answer){
			//answer is your returned value
			console.log(answer);
		});
    }
    //Type appropriate comment here, and begin script below

}

hi,

as i mentioned above there is a variable on a catalog item which refers to IP table....

now the returned sysids I need to store in this variable.. can you please update my client scrpt accordingly

If the field is just called IP, you can do this:

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);
		ga.getXMLAnswer(function(answer){
			//answer is your returned value
			g_form.setValue('ip' , answer);
		});
    }
    //Type appropriate comment here, and begin script below

}

@Kieran Anson not working...

so as part of debubbing I have kept alert in the client script for answer...then I got output like below..

sys_idIN025c3e18db356g6734a7b062f396197d,3cb44c6c345tg650965917a94b96192d

 

please help me to fix this