Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to check iF condition in workflow for MRVS

Piyush291
Tera Contributor

HI,

i have created a catalog item and user MRVS in that, there are 2 fields in multi row

request_type = action and deletion

association = Non government and government

Now i want a condition to check if request type is action or deletion && association is No government then its Yes otherwise No

I tried to write MRVS script but not working

Multi row variable set internal name: declaration_list

1 ACCEPTED SOLUTION

@Piyush291 

you didn't answer my above question

are you saying if any 1 row satisfies that condition then you want to return yes or all rows should satisfy that condition?

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

View solution in original post

13 REPLIES 13

No it should check all rows, if out of 5 mrvs records 3 mrvs rows dont met condition it should say no, If all 5 are meeting conditions then should go to Yes

@Piyush291 

ok so if all rows meet condition then only Yes

update as this

answer = ifScript();
function ifScript() {
	var multiRowVarSet = current.variables.declaration; // variable set internal name
	var rowCount = multiRowVarSet.getRowCount();
	var isValid = false;
	for (var i = 0; i < rowCount; i++) {
		var row = multiRowVarSet.getRow(i);
		var declarationType = row.declaration_type;
		var associate = row.associate;
		if (declarationType == 'Gift' || (declarationType == 'Hospitality' && associate == 'Non Government ')) {
			isValid = true;
		}
		else{
			isValid = false;
		}
	}
	
	if(isValid)
		return 'yes';
	else
		return 'no';
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

I put his code now when i am raising the request it is always taking as Yes, if the conditions are not met even then also, i put associate as Government insted of No government then also it is taking as Yes

answer = ifScript();

function ifScript() {
var multiRowVarSet = current.variables.declaration; // variable set internal name
var rowCount = multiRowVarSet.getRowCount();
var isValid = false;
for (var i = 0; i < rowCount; i++) {
var row = multiRowVarSet.getRow(i);
var declarationType = row.declaration_type;
var associate = row.associate;
if (declarationType == 'Gift' || declarationType == 'Hospitality' && associate == 'Non Government Official') {
isValid = true;
} else {
isValid = false;
}
}

if (isValid)
return 'yes';
else
return 'no';

@Piyush291 

did you check by adding gs.info() in the for loop

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