- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 07:17 AM
Hello,
I have a requirement to auto-populate the IP address field with the Ip address of the computer selected in another field(which is a list collector referencing cmdb_ci).
Thank you.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 03:46 AM
Hi,
update as this
Script Include:
var IP_addresses = Class.create();
IP_addresses.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIpAddress: function(){
var arr = [];
var computer = this.getParameter('sysparm_ip');
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('sys_id', 'IN' ,computer);
gr.query();
while(gr.next()){
arr.push(gr.getValue('ip_address'));
}
return arr.toString();
},
type: 'IP_addresses'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('ipa_rdp');
return;
}
var com = g_form.getValue('names_rdp');
var ga = new GlideAjax('IP_addresses');
ga.addParam('sysparm_name', 'getIpAddress');
ga.addParam('sysparm_ip', com);
ga.getXML(getIp);
}
function getIp(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('ipa_rdp',answer);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 07:26 AM
Hi,
Is this for catalog form or normal form
IP address field/variable is of what type
Also since there could be multiple computers selected then you would get multiple IP addresses
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-03-2022 08:03 AM
Hi Ankur,
It is for catalog form.
The IP address field is a single-line text (also the user must have the feasibility to enter manually in case if IP address doesn't exist)
Yes, since the computer field is a list collector we can get multiple IP addresses.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2022 07:40 PM
Hi,
I believe 1 computer will have only 1 IP address.
Can you share the script you started with and where are you stuck?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-07-2022 03:29 AM
Hello Ankur,
Yes, 1 computer will have only one IP address since we are using List Collector, multiple computers can be selected after that in the IP addresses field the corresponding IP address must be auto-populated(if 1 computer is selected one IP address or if two computers 2 IP address separated with comma ). Please have a look at the attachment.
The difficulty I'm facing is since we are using List collector to get the computers(which is dynamic) which I have no idea. Below is the snippet of code which works fine if we select only one computer it is displaying IP address of it.
Catalog Client Script:-
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == '') {
g_form.setValue(ipa_rdp, " ");
return;
}
if(newValue != oldValue || isLoading){
var com = g_form.getValue('names_rdp');
var ga = new GlideAjax('IP_addresses');
ga.addParam('sysparm_name', 'getIpAddress');
ga.addParam('sysparm_ip', com);
ga.getXML(getIp);
}
function getIp(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('ipa_rdp',answer);
}
}
Script Include:-
var IP_addresses = Class.create();
IP_addresses.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getIpAddress: function(){
var computer = this.getParameter('sysparm_ip');
var gr = new GlideRecord('cmdb_ci_computer');
gr.addQuery('sys_id',computer);
gr.query();
if(gr.next())
{
var i = gr.ip_address;
}
return i;
},
type: 'IP_addresses'
});
Now it needs to work if multiple computers are selected(i.e., those corresponding IP addresses must be populated with comma separation).
Any help, please.