Adding items to List field on GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 04:27 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 05:19 PM
A 'List' fields, is a comma separated list, try building a string of sys_ids separated with ,'s:
var sysIdsOfNetworkInterfaces = "0c26899a6fe9510059fb186e6b3ee413,0eb7ac166f259100fb7f384aea3ee479"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 07:04 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-11-2013 07:30 PM
I like it, a bit more elegant than a simple list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2013 07:12 AM
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?