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

nayanawadhiya1
Kilo Sage

Hello Karan,

We can use like that in the workflow script - 

current.variables.multi_row_variablename.getRowCount() for getting length of array and getRow() for accessing the data of a array.
Please refer below link for better understanding - 

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743684

If possible can you share the script

below is example how we use for normal variable

answer = ifScript();

function ifScript() {
if (current.variables.declaration_type == 'Gift' || current.variables.declaration_type == 'Hospitality' && current.variables.associate == 'Non Government Official') {
return 'yes';
} else {
return 'no';
}
}

It would be like - 

// Syntax for this is gr.variables.table_var.getRow(<ROW NUMBER [i]>) which returns ith row from the multi row variable
// and we are trying to access a cell out of it as below

var row = gr.variables.multirowVariablName.getRow('1');
gs.log( "Fetching Row 1 "+ row.declaration_type);

 You can go through the above link.

Suppose you have a multi-row variable with the named as "server_build_list" and defined with the following fields [with data type]:

  • u_data_center   - String
  • u_how_many - Integer
  • u_storage_size - String

then you can use script as -

var rowLength = current.variables.server_build_list.getRowCount();

for(var i=0;i<rowLength;i++){

var row = current.variables.server_build_list.getRow(i);

var dataCenter = row.u_data_center;

var storageSize = row.u_storage_size

}