Adding items to List field on GlideRecord

Jon_Lind
Kilo Contributor

Hello. I have a CI called "Virtual Server" and it has a field of type List of "Network Interfaces". During my import I would like to find the existing Sys IDs for the Network Interfaces and assign them to the server. I see how to set the value of a Reference field, but not a List field with a GlideRecord.

I'd like something like the following, but unless I've updated the Network Interfaces List on the CI manually it's always undefined:


var gr = new GlideRecord("u_cmdb_ci_virtual_server");
gr.initialize();

var sysIdsOfNetworkInterfaces = ["0c26899a6fe9510059fb186e6b3ee413","0eb7ac166f259100fb7f384aea3ee479"];

gr.u_network_interfaces = sysIdsOfNetworkInterfaces;
gr.insert();


Thanks!
5 REPLIES 5

TJW2
Mega Guru

A 'List' fields, is a comma separated list, try building a string of sys_ids separated with ,'s:

var sysIdsOfNetworkInterfaces = "0c26899a6fe9510059fb186e6b3ee413,0eb7ac166f259100fb7f384aea3ee479"


Michael Kaufman
Giga Guru

Try this out:



var sysIdsOfNetworkInterfaces = ["0c26899a6fe9510059fb186e6b3ee413","0eb7ac166f259100fb7f384aea3ee479"];
for (var i = 0; i < sysIdsOfNetworkInterfaces.length; i++) {
var gr = new GlideRecord("u_cmdb_ci_virtual_server");
gr.initialize();
gr.u_network_interfaces = sysIdsOfNetworkInterfaces<i>;
gr.insert();
}


I like it, a bit more elegant than a simple list.


I have one Virtual Server with two Network Interfaces, but I think that this solution would create two virtual servers with a single record in the plural network interfaces field?