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

Brad Bowman
Kilo Patron
Kilo Patron

Since this is an if script, and you are returning 'yes' or 'no' during the first iteration of the loop, you are only getting the answer based on the first row.  If you are doing this in a (legacy) Workflow, move this script to the Approval - Group activity, pushing the group sys_id, or that stored in a system property, to the answer from each row:

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);
        answer.push('sys_id of group a');
    } else {
        answer.push('sys_id of group b');
    }
}

 This way if both AB and BC are requested in the MRVS, both groups will be added to the approval.

DASAMANDAMS
Tera Contributor

i tried in approval group activity however it is not working and log shows as Cannot find function push in object servicenow how can we achieve this

This follows the suggested text on a new script in an approval activity

BradBowman_0-1731516358147.png

What does your script look like?

Hi @Brad Bowman  
These is the below script that i am using

var answer = [];

 

// 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
    }
}