- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:01 PM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:12 PM
I think you are suppose to parse it to JSON before the loop. Also can you try the for loop?
var mrvsValues = current.variables.mrvs_sys_ids;
gs.info("payload = "+ mrvsValues);
var payloadParsed = JSON.parse(mrvsValues); //this gets my input readable
for(var i in payloadParsed)
{
gs.info('Parsed: '+payloadParsed[i]);
var grAsset = new GlideRecord('alm_hardware');
grAsset.addQuery('sys_id', payloadParsed[i]);
grAsset.query();
if (grAsset.next()){
grAsset.install_status = '6';
grAsset.update();
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:16 PM
Hello @Lon Landry4
You can refer to the below script and give a shot.
var mrvsValues = current.variables.mrvs_sys_ids;
gs.info("payload = " + mrvsValues);
mrvsValues.forEach(function (value) {
var payloadParsed = JSON.parse(value); // Parse each element of the array
gs.info('Parsed: ' + payloadParsed);
var grAsset = new GlideRecord('alm_hardware');
grAsset.addQuery('sys_id', payloadParsed);
grAsset.query();
if (grAsset.next()) {
grAsset.install_status = '6';
grAsset.upda
te();
}
});
Please let me know your views on this and mark helpful and correct if it's helpful to you.
Thank you,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:21 PM
I think the issue is with how you are handling the payload for the MVRS. The payload for a Multi-Row Variable Set is an Array of Objects, so you need to treat it as such. Each row in the Multi-Row Variable Set is represented as a single Object in the Array. So if you have 3 rows, there will be three Objects in there. For each of the Objects, there are key-value pairs that represent the MVRS field name and value.
With all that said - your code will need to look something like this.
var mrvsValues = current.variables.mrvs_sys_ids;
var payloadParsed = JSON.parse(mrvsValues); //this gets my input readable
for (var row in payloadParsed) {
// Replace 'element' with the name of the field in your MVRS that contains the sys_id of the asset record you want to update.
updateAsset(payloadParsed[row].element);
}
function updateAsset(assetID) {
var grAsset = new GlideRecord('alm_hardware');
if (grAsset.get(String(assetID))){
grAsset.install_status = '6';
grAsset.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2023 01:26 PM
You could also make the code above more efficient by just making one GlideRecord call instead of multiple.
var mrvsValues = current.variables.mrvs_sys_ids;
var payloadParsed = JSON.parse(mrvsValues); //this gets my input readable
var idsToUpate = [];
for (var row in payloadParsed) {
// Replace 'element' with the name of the field in your MVRS that contains the sys_id of the asset record you want to update.
idsToUpate.push(payloadParsed[row].element);
}
updateAssets(idsToUpate.toString());
function updateAssets(assetIDs) {
var grAsset = new GlideRecord('alm_hardware');
grAsset.addEncodedQuery('sys_idIN'+assetIDs);
if (grAsset.hasNext()){
grAsset.install_status = '6';
grAsset.updateMultiple();
}
}