Run in Parallel

The Run in Parallel action is used to run multiple action chains in parallel, and it can also be used to wait for their results to produce a combined result.

The actions to run for each sequence are placed within an asyn() method, and the value returned by the asyn() method is put into the array returned by the Run in Parallel action. The first element of the returned array contains the result from the first asyn() method, the second element contains the result from the second asyn() method, and so on.

Here's an example of the Run in Parallel action, which returns its results in an array named empInfo. In parallel, the action makes REST calls to get an employee's office location, department, and team. The employee's information is then displayed:

async run(context, { office_ip = 1, department_ip = '1', team_ip = 2 }) {
      const { $application, $flow, $page } = context;

      const empInfo = await Promise.all([
        async () => {

          const callRestGetOfficesResult = await Actions.callRest(context, {
            endpoint: 'businessObjects/get_Offices',
            uriParams: {
              'Offices_Id': office_ip,
            },
          });

          return callRestGetOfficesResult.body.location;
        },
        async () => {

          const callRestGetDepartmentResult = await Actions.callRest(context, {
            endpoint: 'businessObjects/get_Department',
            uriParams: {
              Department_Id: department_ip,
            },
          });

          return callRestGetDepartmentResult.body.name;
        },
        async () => {
          const callRestBusinessObjectsGetTeamResult = await Actions.callRest(context, {
            endpoint: 'businessObjects/get_Team',
            uriParams: {
              'Team_Id': team_ip,
            },
          });

          return callRestBusinessObjectsGetTeamResult.body.name;
        },
      ].map(sequence => sequence()));

      await Actions.fireNotificationEvent(context, {
        summary: 'Employee Info',
        message: 'LOCATION: ' + empInfo[0] + ' DEPARTMENT: ' + empInfo[1] + ' TEAM: '+ empInfo[2],
      });
    }

Return Values

This action returns an array (empInfo) with the first element (index 0) containing the value returned from the first asyn() method, the second element containing the value from the second asyn() method, and the third element containing the value from the third asyn() method.