How do I get the values of multi row variable set in workflow.

Rashmi11
Tera Contributor

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';
 }
}
}

 

find_real_file.png

1 ACCEPTED SOLUTION

John Dewhurst
Kilo Guru

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";
})();

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update script as this

answer = ifScript();

function ifScript() {
	var mrvs = current.variables.Grants;//replace with the internal name of your MRVS
	var found = false;
	var parser = JSON.parse(mrvs);
	for(var i=0;i<parser.length; i++){//for each row in the MRVS
		if(parser[i].level.toString() == 'Project')
		{
			found = true;
			break;
		}
		else
			found = false;
	}

	if(found)
		return 'yes';
	else
		return 'no';	
}

regards
ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

No luck, value is still undefined

Hi,

share your latest scripts and ensure you use correct variable names

I assume you are writing this script in workflow of your catalog item

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

answer = ifScript();
function ifScript() {
    var mrvs = current.variables.Grants;//replace with the internal name of your MRVS
    var found = false;
    var parser = JSON.parse(mrvs);
    for(var i=0;i<parser.length; i++){//for each row in the MRVS
        if(parser[i].level.toString() == 'Project')
        {
            found = true;
            break;
        }
        else
            found = false;
    }

    if(found)
        return 'yes';
    else
        return 'no';    
}

============

Variable name etc is correct.