how to pass sys ids from script include to client script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2021 11:08 AM
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
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2021 12:46 PM
Hi,
Did my answer help or do we need to follow up on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2021 11:25 AM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-12-2021 11:52 AM
sys_idIN025c3e18db356g6734a7b062f396197d,3cb44c6c345tg650965917a94b96192d
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2021 12:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-15-2021 03:30 AM
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