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

Enhanced Solution: Pull Company Record for Each Approver

Since each approver is associated with a company, you need to:

 

Retrieve the list of approvers from the MRVS.

Fetch the company record for each approver.

Create approval records with company details.

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?

 

As you said time difference is not a matter but its waiting for first approval response to create 2nd approval that's where I am struggling.

Enhanced Solution: Pull Company Record for Each Approver

Since each approver is associated with a company, you need to:

 

Retrieve the list of approvers from the MRVS.

Fetch the company record for each approver.

Create approval records with company details.

 

var approverList = [];
var gr = new GlideRecord('sc_multi_row_variable_set'); // Update with your actual MRVS table
gr.addQuery('request_item', current.sys_id);
gr.query();

while (gr.next()) {
var approverData = {};
approverData.approver = gr.getValue('approver'); // Assuming 'approver' field exists
approverData.company = getCompanyForUser(approverData.approver); // Fetch company
approverList.push(approverData);
}

// Function to get the company for a user
function getCompanyForUser(userId) {
var userRec = new GlideRecord('sys_user');
if (userRec.get(userId)) {
return userRec.getValue('company'); // 'company' field should reference the Company table
}
return '';
}

 

The script retrieves each approver's details and fetches their company record.

The company field is extracted from the sys_user table.

2. Store the Approver List in a Flow Variable

Save the approverList array as a variable in Flow Designer.

This will be used in the next step to create approval records dynamically.

3. Create Approval Records Including Company Info

Use "Create Record" action inside Flow Designer.

Table: sysapproval_approver

Set Fields:

Approver: approverData.approver

Company: approverData.company

State: Pending

Source Table: Requested Item (sc_req_item)

Source Record: current.sys_id

And another add on maybe 

Alternative: Use Flow Designer’s "Ask for Approval" with Company Data

If using Flow Designer without scripting:

 

Add an Action → Use "Lookup Records" on sys_user table.

Match approver email/ID with the user record.

Extract the company field and store it as a variable.

Pass the variable when creating approval records.

Final Outcome

All approvals are submitted at the same time (parallel processing).

Each approver's company is automatically included in the approval record.

Eliminates need for a sequential For Each loop, improving efficiency.

Thanks @jcmings 

VenkyKshatriy2_0-1739268788999.png

You talking abt the ASK APPROVAL ACTION, I unable to find the wait check box.

Is the Wait checkbox checked on the Ask for Approval? You may need to un-check that.