- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 05:08 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:46 PM
HI @Lon Landry4 ,
I trust you are doing great.
Here's a revised version of your code snippet with the necessary adjustments:
var maps = [
{
'asset_tag': 'first_asset_tag',
'serial_number': 'first_serial_number',
'mac_address': 'first_mac_address',
},
{
'asset_tag': 'second_asset_tag',
'serial_number': 'second_serial_number',
'mac_address': 'second_mac_address',
},
{
'asset_tag': 'third_asset_tag',
'serial_number': 'third_serial_number',
'mac_address': 'third_mac_address',
},
{
'asset_tag': 'fourth_asset_tag',
'serial_number': 'fourth_serial_number',
'mac_address': 'fourth_mac_address',
},
{
'asset_tag': 'fifth_asset_tag',
'serial_number': 'fifth_serial_number',
'mac_address': 'fifth_mac_address',
},
];
var grComputer = new GlideRecord('cmdb_ci_computer');
for (var i = 0; i < maps.length; i++) {
var map = maps[i];
var allFieldsEmpty = true; // Flag to track if all fields are empty
// Check if any field in the map has a non-null value
for (var field in map) {
if (map[field] && current.variables[map[field]]) {
allFieldsEmpty = false; // At least one non-empty field found
break;
}
}
// If at least one non-empty field found, create the record
if (!allFieldsEmpty) {
grComputer.initialize();
for (var field in map) {
// Only set values for non-empty fields
if (map[field] && current.variables[map[field]]) {
grComputer.setValue(field, current.variables[map[field]]);
}
}
grComputer.install_status = '6';
grComputer.hardware_substatus = 'available';
// Insert the record into cmdb_ci_computer table
grComputer.insert();
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2024 07:46 PM
HI @Lon Landry4 ,
I trust you are doing great.
Here's a revised version of your code snippet with the necessary adjustments:
var maps = [
{
'asset_tag': 'first_asset_tag',
'serial_number': 'first_serial_number',
'mac_address': 'first_mac_address',
},
{
'asset_tag': 'second_asset_tag',
'serial_number': 'second_serial_number',
'mac_address': 'second_mac_address',
},
{
'asset_tag': 'third_asset_tag',
'serial_number': 'third_serial_number',
'mac_address': 'third_mac_address',
},
{
'asset_tag': 'fourth_asset_tag',
'serial_number': 'fourth_serial_number',
'mac_address': 'fourth_mac_address',
},
{
'asset_tag': 'fifth_asset_tag',
'serial_number': 'fifth_serial_number',
'mac_address': 'fifth_mac_address',
},
];
var grComputer = new GlideRecord('cmdb_ci_computer');
for (var i = 0; i < maps.length; i++) {
var map = maps[i];
var allFieldsEmpty = true; // Flag to track if all fields are empty
// Check if any field in the map has a non-null value
for (var field in map) {
if (map[field] && current.variables[map[field]]) {
allFieldsEmpty = false; // At least one non-empty field found
break;
}
}
// If at least one non-empty field found, create the record
if (!allFieldsEmpty) {
grComputer.initialize();
for (var field in map) {
// Only set values for non-empty fields
if (map[field] && current.variables[map[field]]) {
grComputer.setValue(field, current.variables[map[field]]);
}
}
grComputer.install_status = '6';
grComputer.hardware_substatus = 'available';
// Insert the record into cmdb_ci_computer table
grComputer.insert();
}
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 04:22 AM
Thank you so much for your help. I have been struggling with JavaScript as I get into more advanced concepts.
I hope to be able to take the official ServiceNow coding course this year.
Any recommendations for ServiceNow JavaScript training beyond Chuck Tomasi's or Earl Duque's JavaScript training?
(I do not create custom apps, all of my work is done in global application with an emphasis on ITSM.
Thanks again,
Lon