The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Send the 5 approval records at the same time

Venky Kshatriy2
Tera Contributor

Hi Team,

 

I have created on catalog item, that item contains the MRVS, inside the MRVS we have the approver's values.  i am sending the approvals by using the Flow designer, for MRVS to get one by one approval i used FOR EACH Logic ,the approval records created but I WANT TO CRATE THE ALL APPROVAL RECORDS AT A TIME.

 

Ex: MRVS contains the 5 records now we have 5 approvers i need to create 5 approvals records same time.

 

If any one knows could pls help on this 

Advance thanks Team

VenkyKshatriy2_0-1739186861410.png

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Venky Kshatriy2 

 for (var i = 0; i < vk.length; i++) {
      var approver = vk[i].engagement_partner;
      gs.log('first approver'+approver);
      approvers.push({
          sysapproval: requestId,
          approver: approver,
          state: 'requested
 });
      gs.log('second approver'+approvers);
}
Remove following code:
var approvalGr = new GlideRecord('sysapproval_approver');
      approvalGr.initialize();
   

    for (var j = 0; j < approvers.length; j++) {
      gs.log('view thw rule')
      var vj = approvers[j];
      gs.log('mainvalues'+vj);
      var approval = approvalGr.createRecord();
      approval.sysapproval = vc;
      approval.approver = vj;
      approval.state = 'requested';
      approval.insert();
}
instead, add following:
if (approvers.length > 0) {
    var approvalGr = new GlideRecord('sysapproval_approver');
    approvers.forEach(function(approvalData) {
    approvalGr.initialize();
    approvalGr.sysapproval = approvalData.sysapproval;
    approvalGr.approver = approvalData.approver;
    approvalGr.state = approvalData.state;
    approvalGr.insert();
}
else gs.info('No approvers found, skipping approval record creation.');
});

View solution in original post

22 REPLIES 22

Ankur Bawiskar
Tera Patron
Tera Patron

@Venky Kshatriy2 

I believe you want to fetch all the approvers i.e. combine all from each row and send only once?

If yes then you can use flow variable and store the approvers in it and then use Ask for Approval flow action

Please start with the above and let me know if any help required.

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

Thanks @Ankur Bawiskar 

VenkyKshatriy2_0-1739187570907.png

to store all the approvers right now we don't have the particular flow variable as per my knowledge. Is any flow variable is available to store 2 or more values. In single flow variable

@Venky Kshatriy2 

you can create flow variable of type string and then while setting you can concatenate the approvers from each row of MRVS when you parse

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

Actually Its not creating one after one. The 2nd is waiting for the first approval response once it is full filled then only its going to create 2nd approval. That's what the issue for me and  that's where I am struggling.?

Community Alums
Not applicable

Hi @Venky Kshatriy2 ,

will suggest you to replase for each condition with Custom Script Action.

and use following script:

    var mRVS = current.variables.mrvs_field_name; 

    var approvers = [];

    for (var i = 0; i < mRVS.length; i++) {
      var approver = mRVS[i].approver; // Replace with the field that contains the approver's record
      approvers.push(approver);
}

    var approvalGr = new GlideRecord('sys_approval'); 
    approvalGr.initialize(); 

    for (var j = 0; j < approvers.length; j++) {
      var approval = approvalGr.createRecord(); 
      approval.request = current.sys_id; 
      approval.approver = approvers[j]; 
      approval.state = 'pending'; 
      approval.insert(); 
}

return 'Approval records created successfully';