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 access Multirow Variable set variable value entire columns values

DASAMANDAMS
Tera Contributor

Hi Team, 

I have requirement to trigger the approval based on the multirow variable i.e.  Item requested variable value (please refer screenshot)


if Item requested value is AB = Approval should trigger to group A

If Item requested value is BC= Approval should trigger to group B 

etc. having multiple condition

 

I am using below script, and it is working fine for 1st column and I am stuck in accessing 2nd column and so on can someone assist me how can we access all the column values

 

 

answer = ifScript();

 

  function ifScript() {
var mrvsParsed = JSON.parse(current.variables.oracle_custom_roles.toString());
for(var i=0;i<mrvsParsed.length; i++){

 

var system = mrvsParsed[i].item_requested;
gs.info('MRVS' +system);

if (system =='AB'){
gs.info('INSIDEMRVS' +system);

 

return 'yes';
     }
  else{
  return 'no';
  }
}
  }

5 REPLIES 5

You don't need/want to declare the answer array as that is already inherent in the Approval activity, and you have an errant space and capitalization in the push

// Assuming current.variables.oracle_custom_roles contains the data as a string.
var rolesArray = JSON.parse(current.variables.oracle_custom_roles.toString());

// Loop through each item in the rolesArray
for (var i = 0; i < rolesArray.length; i++) {
    var businessFlow = rolesArray[i].business_flow.toString();  // Extract the business_flow value

    // Check if the business_flow is 'P2P'
    if (businessFlow == 'P2P') {
        answer.push('31ea3d7e1b7b8e582be1eac82d4bcb09');  // Push specific value to answer array
    }
    if (businessFlow == 'R2P') {
    answer.push('31ea3d7e1b7b8e582be1eac82d4bcb09');  // Push specific value to answer array
    }
}

 although in this script you are pushing the same (group?) sys_id regardless of the business_flow.