- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:45 PM
I may need two scripts, one for asset_tags & one for serial numbers.
This is for creating assets in Workflow.
//Don't try this code a 20 or so, junk records are created.
var grComputer = new GlideRecord('alm_hardware');
var fields = ["first_asset_tag", "first_serial_number", "second_asset_tag", "second_serial_number", "third_asset_tag", "third_serial_number""] ";
var last = fields.pop();
fields.forEach(function(field, i) {
var nextField = fields[i+1] || last;
grComputer.initialize();
grComputer.asset_tag = current.variables.fields;
grComputer.serial_number = current.variables.fields;
grComputer.insert();
});
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:52 PM
Instead of using array, it would be better to use JSON object to store value as key-pair, while fetching it from the variables, then iterate through the object to add/update fields in the hardware table.
Its much more reliable way of handling the data, instead of using array to store two distinct information.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:56 PM
The question doesn't provide much context, share more details about the problem you are facing, the use of array doesn't seem right.
How are you accessing these values, or these are static?
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:11 PM
Good point,
I am trying to find a way to loop thru variable fields, the variables create a new record & update fields on the hardware table (not all fields are shown). There may be one asset being created or hundreds of assets created.
All of the variables start with a number & contain _asset_tag or _serial_number.
The variables are in sequence on the form.
So, I am wondering if I can find _asset_tag & _serial_number sequentially as opposed to have to write code for each field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 07:52 PM
Instead of using array, it would be better to use JSON object to store value as key-pair, while fetching it from the variables, then iterate through the object to add/update fields in the hardware table.
Its much more reliable way of handling the data, instead of using array to store two distinct information.
Aman Kumar