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

Hi,

Did my answer help or do we need to follow up on this?

Vishwanath Nam1
Tera Contributor

Hi try this,

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.getXML(callfunction);

function callfunction(response) {
var obj = response.responseXML.documentElement.getAttribute("answer");

console.log(obj);

}

}

@Vishwanath Namgonde tried the kieran script but not working...tried using alert I got like below

sys_idIN025c3e18db356g6734a7b062f396197d,3cb44c6c345tg650965917a94b96192d

 

 

Sathwik1
Tera Expert

@asifnoor 

Tejas Tamboli
Giga Guru

Hi Sathwik,

You can try like this: 

Please refer below code do changes accordingly:

Let me know if you are getting the expected output...

Script Include: It should be client callable

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 answer.toString();
    },

    type: 'Firewall_IP'
});

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);
        ga.getXMLAnswer(function(answer){

        alert(answer);

        //To loop through the sys_id
        answer.split(',').forEach(function(value, /*Optional*/ index, /*Optional*/ Arr){

        alert(value);

    }
    //Type appropriate comment here and begin script below

}

 

 

I hope this will help you.


Mark ✅ Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.

Thanks & Regards,
Tejas Tamboli