- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 01:38 AM
How can I access a particular field value of a Multi Row variable set to a workflow?
I need the value of Level in workflow to trigger approval.. I tried below but its returning undefined:
answer = ifScript();
var mrvs = current.variables.Grants;//replace with the internal name of your MRVS
var mrs = g_form.variables.Grants;
workflow.info('mrs'+mrs);
workflow.info('mrvs'+mrvs);
function ifScript()
{
var rowCount = mrvs.getRowCount();
for(var i=0;i<rowCount; i++){//for each row in the MRVS
var row = mrvs.getRow(i);
workflow.info('row'+row);
workflow.info('row.level'+row.level);
if(row.level == 'Project')
{
return 'yes';
}
else
{
return 'no';
}
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 06:35 AM
Leveraging the Array.some method makes this much cleaner
answer = (function ifScript() {
return JSON.parse(current.variables.Grants)
.some(function(row){
return row.level === "Project";
}) ? "yes": "no";
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 02:45 AM
Hi,
did you add gs.info() and check?
what type of variable is level ?
Is it drop down? If yes then you should compare the choice value of it
Add gs.info() and share the logs
answer = ifScript();
function ifScript() {
var mrvs = current.variables.Grants;//replace with the internal name of your MRVS
gs.info("mrvs data" + mrvs);
var found = false;
var parser = JSON.parse(mrvs);
for(var i=0;i<parser.length; i++){//for each row in the MRVS
gs.info("level value" + parser[i].level);
if(parser[i].level.toString() == 'project')
{
found = true;
break;
}
else
found = false;
}
if(found)
return 'yes';
else
return 'no';
}
regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 10:39 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-31-2022 06:35 AM
Leveraging the Array.some method makes this much cleaner
answer = (function ifScript() {
return JSON.parse(current.variables.Grants)
.some(function(row){
return row.level === "Project";
}) ? "yes": "no";
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 02:21 AM
hello Rashmi,
you can try this
ifScript();
var mrvs = JSON.parse(current.variables.Grants);//replace with the internal name of your MRVS
function ifScript()
{
for(var i=0;i<mrvs.length; i++){//for each row in the MRVS
if(mrvs[i].level == 'Project')
{
return 'yes';
}
else
{
return 'no';
}
}
Hope this helps
please mark my answer correct if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2022 02:41 AM
Hi Mohit,
Looks like some issue with Json. Its giving SyntaxError: Unexpected token: u
Tried defining the string variable and checking the log but mrvs value is undefined.