- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 07:00 AM - edited 01-20-2024 08:02 AM
The sys ID shown cannot be found on any related tables.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 10:55 AM
Here's the approach I always use to loop through an MRVS in a Workflow script, adapted to your example:
var rqstdFor = current.variables.requested_for_full_name.name.getDisplayValue();
//retrieve the entire MRVS contents
var mrvs = current.variables.assets_assigned;
var rowCount = mrvs.getRowCount();
//loop through the MRVS contents
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
//get corresponding asset on Hardware table
var asset = new GlideRecord ('alm_hardware');
if (asset.get(row.assets_assigned_to_this_user)) {
//Update corresponding asset on Hardware table
asset.assigned_to = rqstdForName;
asset.install_status='1';
asset.substatus ='';
asset.update();
} else { //if no record found on Hardware table
gs.error('No corresponding asset found for MRVS value:'+row.assets_assigned_to_this_user);
}
}
although if requested_for_full_name is a reference type variable, then rqstdFor should just be
var rqstdFor = current.variables.requested_for_full_name;
since the assigned_to field on the alm_hardware table is a reference type field, it needs a sys_id as its value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 10:55 AM
Here's the approach I always use to loop through an MRVS in a Workflow script, adapted to your example:
var rqstdFor = current.variables.requested_for_full_name.name.getDisplayValue();
//retrieve the entire MRVS contents
var mrvs = current.variables.assets_assigned;
var rowCount = mrvs.getRowCount();
//loop through the MRVS contents
for (var i=0; i<rowCount; i++) {
var row = mrvs.getRow(i);
//get corresponding asset on Hardware table
var asset = new GlideRecord ('alm_hardware');
if (asset.get(row.assets_assigned_to_this_user)) {
//Update corresponding asset on Hardware table
asset.assigned_to = rqstdForName;
asset.install_status='1';
asset.substatus ='';
asset.update();
} else { //if no record found on Hardware table
gs.error('No corresponding asset found for MRVS value:'+row.assets_assigned_to_this_user);
}
}
although if requested_for_full_name is a reference type variable, then rqstdFor should just be
var rqstdFor = current.variables.requested_for_full_name;
since the assigned_to field on the alm_hardware table is a reference type field, it needs a sys_id as its value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 11:24 AM
Thanks for the help, this worked. I have been revisiting Chuck Tomasi's training on youtube for this. But, I could not wrap my head around it this... I will keep up with the Training. Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2024 12:26 PM
You are welcome!