---
category: [Administration & Integrations, Administration & Integrations/Custom Integrations & Apps, Platform and Product Extensions, Platform and Product Extensions/Workday Extend, Platform and Product Extensions/Integration]
keyword: [Extend, Model Components, Extend Business Objects, MCBO, Model Component Business Objects, Business Objects, Model BO]
nav: wcp_docs
parent_url: /wcp_docs/
title: >- 
  Example: Order of Responses in Bulk Operations on Business Objects
layout: subsection
---

When you submit a bulk request using a Workday Extend business object REST API, the order of the responses received matches the order of the requests in the bulk operation.

### Scenario

<a id="context_N10060_N10059_N10001"></a>
By using constrained security on an Extend business object, you can generate errors that you can use to match individual requests within a bulk operation with their corresponding responses.

In this sample business object, the Manager role-based security group has Modify access to the `BulkWorkersDomain` security domain. As a result, when you sign in as Logan McNeil, records with a `workerStarter` of Betty Liu, Maria Cardoza, or Jacqueline Desjardins are accepted. All other records generate a `"status": 400` error.

```
{
"id": 1,
"name": "BulkWorkersList",
"label": "Bulk Workers List",
"defaultSecurityDomains": [
"BulkWorkersDomain"
],
"defaultCollection": {
"name": "bulkWorkersLists",
"label": "Bulk Workers Lists"
},
"fields": [
{
"id": 1,
"name": "workerStarter",
"label": "Starting Worker",
"type": "SINGLE_INSTANCE",
"target": "WORKER",
"secureByTarget": true
},
{
"id": 2,
"name": "workerHandoff",
"label": "Handoff Worker",
"type": "SINGLE_INSTANCE",
"target": "WORKER"
}
]
}
```

<b>Note:</b> Extend applies constrained security at the business object level, and applies the constraint against the `workerStarter` field, as configured by the `secureByTarget` attribute. The constraint first determines if you can access the object at all. If you can access the object, field-level security determines if you can view or modify each individual field.

### Steps

1.  <a id="step_N1008C_N10089_N10059_N10001"></a>Define an outbound endpoint in your PMD for the bulk operation.

    ```
    {
    "baseUrlType": "BUSINESS-OBJECT",
    "name": "workerPOST",
    "authType": "sso",
    "url": "/bulkWorkersLists?bulk=true",
    "httpMethod": "POST",
    "onSend": "<% var dataPayload = json:create(json:attribute('data', self.data));
    console.info(dataPayload);
    return dataPayload;
           %>"
    }
    ```

    The `onSend` event handler constructs the request body for the outbound endpoint.

2.  <a id="step_N100A1_N10089_N10059_N10001"></a>The outbound endpoint submits this data payload to the business object REST API as a bulk request.

    ```
    {
    "data": [
      {
          "workerStarter": {
              "id": "cc7fb31eecd544e9ae8e03653c63bfab"
          },
          "workerHandoff": {
              "id": "0d32ccd079004a1c8954caf934f220d6"
          }
      },
      {
          "workerStarter": {
              "id": "de52fbe58bc84c8b90883502f9f868ed"
          },
          "workerHandoff": {
              "id": "c0831f1b82954a37bd9a0ad85fb85367"
          }
      },
      {
          "workerStarter": {
              "id": "3bcc416214054db6911612ef25d51e9f"
          },
          "workerHandoff": {
              "id": "dec5c2732b764d0eb1f7fe8e2e072ce9"
          }
      }
    ]
    }
    ```



### Result

<a id="result_N1008D_N10059_N10001"></a>
You receive this response:

```
{
"data": [
  {
      "body": {
          "id": "2ce03122a244900d1d64234583810000",
          "descriptor": "Bulk Workers List",
          "workerStarter": {
              "descriptor": "Maria Cardoza",
              "id": "cc7fb31eecd544e9ae8e03653c63bfab"
          },
          "workerHandoff": {
              "descriptor": "Amit Kapoor",
              "id": "0d32ccd079004a1c8954caf934f220d6"
          }
      },
      "status": 201
  },
  {
      "body": {
          "error": "invalid request: validation errors",
          "errors": [
              {
                  "error": "invalid instances for instance set",
                  "code": "A5",
                  "field": "workerStarter",
                  "path": "workerStarter",
                  "internalMessage": "One or more instances of type 'Relationship (1$3)' were not valid for the Prompts and Constraints Workset: 15$2000142"
              }
          ]
      },
      "status": 400
  },
  {
      "body": {
          "id": "2ce03122a244900d1d64234583810001",
          "descriptor": "Bulk Workers List",
          "workerStarter": {
              "descriptor": "Betty Liu",
              "id": "3bcc416214054db6911612ef25d51e9f"
          },
          "workerHandoff": {
              "descriptor": "Alex Grossman",
              "id": "dec5c2732b764d0eb1f7fe8e2e072ce9"
          }
      },
      "status": 201
  }
],
"total": 3,
"responseHeaders": {
  "date": [
      "Mon, 21 Nov 2022 14:30:10 GMT"
  ],
  "stricttransportsecurity": [
      "max-age=31536000; includeSubDomains; preload",
      "max-age=15638400; includeSubDomains",
      "max-age=15638400; includeSubDomains"
  ],
  "transferEncoding": [
      "chunked"
  ],
  "wdcommonrequestid": [
      "F5S|39452B18|637B8B71"
  ],
  "connection": [
      "keep-alive"
  ],
  "omsxoversion": [
      "2022.47.1084.????"
  ],
  "contentType": [
      "application/json"
  ],
  "cacheControl": [
      "no-cache"
  ],
  "wdstatrequestid": [
      "bd342069-f4f8-4f76-9b6a-8928a667ebe2"
  ],
  "statusCode": [
      "207"
  ]
}
}
```

Note that the order of the data in the body of the response matches the order of the data in the body of the request.

### Next Steps

<a id="postreq_N10099_N10059_N10001"></a>
You can use PMD scripting to assemble a response document with the input elements and updated status codes. You can also filter out the successful rows to return only error records. This page would be part of a self-referencing flow definition.

```
{
"id": "testBulkErrors",
"script": "<%
       var getGridRowsWithStatus = function(){
           //Get the Grid data and prepare a simplified format for passing to the next page
           var myGridRows = bulkRows.getRows();
           var newGridRows = myGridRows.map(  tempRow =>{ {
               'column1': tempRow.childrenMap.colStart.value[0],
               'column2': tempRow.childrenMap.colHandoff.value[0],
               'status' : 201,
               'message' : 'good'
           } });
           //Now loop through the responses, applying the correct response to each row from the grid
           var rowCounter = 0;
           for (var i : newGridRows) {
               newGridRows[rowCounter].status =  workerPOST.data[rowCounter].status;
                   if (workerPOST.data[rowCounter].status!=201)
                      {newGridRows[rowCounter].message =  workerPOST.data[rowCounter].body.error;
                   };
                      rowCounter=rowCounter+1
           };
           //Now filter out the grid rows that went through, and only pass the error records back
           newGridRows = newGridRows.filter(tempRow=>{tempRow.status!=201});
           return newGridRows
       }
       %>",
"endPoints": [
{
"baseUrlType": "workday-wql",
"name": "sanFranciscoWorkers",
"authType": "sso",
"url": "<% var myWQL = 'SELECT legalFullName, workdayID FROM allWorkers WHERE location=d13a7c46a06443c4a33c09afbdf72c73'.pathEncode();
return myWQL;              
        %>"
}
],
"outboundData": {
"outboundEndPoints": [
{
  "baseUrlType": "BUSINESS-OBJECT",
  "name": "workerPOST",
  "authType": "sso",
  "url": "/bulkWorkersLists?bulk=true",
  "httpMethod": "POST",
  "onSend": "<% var dataPayload = json:create(json:attribute('data', self.data));
  return dataPayload;
             %>"
},
{
  "type": "outboundVariable",
  "name": "RestResponse",
  "variableScope": "flow",
  "values": [
    {
      "outboundPath": "wholeResponse",
      "value": "<% json:asJSON(workerPOST) %>"
    },
    {
      "outboundPath": "StatusFlagError",
      "value": "<%   var rowCounter = 0;
      var StatusOut = false;
      for (var i : bulkRows.getRows()) {
          if (!(workerPOST.data[rowCounter].status==201))
              {StatusOut=true
          };
              rowCounter=rowCounter+1
      };
      return StatusOut;%>"
    },
    {
      "outboundPath": "RowsMap",
      "value": "<%   getGridRowsWithStatus();
                %>"
    }
  ]
}
]
},
"presentation": {
"title": {
  "type": "title",
  "label": "Workday Extend"
},
"body": {
  "type": "section",
  "horizontal": false,
  "children": [
    {
      "type": "text",
      "enabled": false,
      "label": "Enter some Rows Below",
      "value": "If you are logged in as Logan and applied Manager as the group on the Security Domain, using Logan's direct reports in the Starting Worker column will go through and anyone else will not (Betty Liu is a good example). Good records will be saved. If there are error records you will be rerouted to this page with the good records removed, and the error records presented with the error code. Fix the errors and click OK again to reprocess"
    },
    {
      "type": "text",
      "enabled": false,
      "label": "Limits",
      "value": "Please use this design pattern below 100 records in the grid. For sample code to limit a grid size, this has been limited to 10 records. A separate Design pattern will be created using Orchestrations for larger datasets."
    },
    {
      "type": "grid",
      "id": "bulkRows",
      "rows": "<% flowVariables.RowsMap %>",
      "isArrayOutBinding": true,
      "onRowAdd":"<%
                  if (bulkRows.getRows().size()>10){
                      bulkRows.setDoNotAdd(true)
      }else
                  {
                      bulkRows.setDoNotAdd(false)
                  }
                  %>",
      "rowVariableName": "rosterRow",
      "columns": [
        {
          "type": "column",
          "columnId": "colStart",
          "label": "Starting Worker",
          "cellTemplate": {
            "type": "dropdown",
            "values": "<% sanFranciscoWorkers.data %>",
            "displayKey": "legalFullName",
            "idKey": "workdayID",
            "valueOutBinding": "workerPOST.[].workerStarter.id",
            "selectedValues": "<% [rosterRow.column1] ?? []  %>"
          }
        },
        {
          "type": "column",
          "columnId": "colHandoff",
          "label": "Handoff Worker",
          "cellTemplate": {
            "type": "dropdown",
            "values": "<% sanFranciscoWorkers.data %>",
            "displayKey": "legalFullName",
            "idKey": "workdayID",
            "valueOutBinding": "workerPOST.[].workerHandoff.id",
            "selectedValues": "<% [rosterRow.column2] ?? []  %>"
          }
        },
        {
          "type": "column",
          "columnId": "colStatus",
          "label": "Status",
          "cellTemplate": {
            "type": "text",
            "value": "<% rosterRow.status ?? ''  %>",
            "enabled": false
          }
        },
        {
          "type": "column",
          "columnId": "colMessage",
          "label": "Error Message",
          "cellTemplate": {
            "type": "text",
            "value": "<% rosterRow.message ?? ''  %>",
            "enabled": false
          }
        }
      ]
    }
  ]
},
   "footer": {
    "type": "footer",
    "children": [
      {
        "type": "richText",
        "enabled": "false",
        "value": "Powered By Workday Extend"
      }
    ]
   }
 }
}
```

Make sure that the `"workday-wql"` data provider is included in the `dataProviders` array in the AMD file:

```
"dataProviders": [
{
"key": "WORKDAY-EXPENSE",
"value": "https://api.workday.com/expense/v1"
},
{
"key": "MERCHANT-OBJECT",
"value": "<% 'https://api.workday.com/apps/' + site.applicationId + '/v1' %>"
},
{
"key": "workday-wql",
"value": "https://api.workday.com/wql/v1/data?query="
},
{
"key": "BUSINESS-OBJECT",
"value": "<% 'https://api.workday.com/apps/' + site.applicationId + '/v1' %>"
},
{
"key": "Orchestration",
"value": "<% 'https://api.workday.com/orchestrate/v1/apps/' + site.applicationId + '/orchestrations' %>"
}
]
```

### Related Information

[Reference: Business Object API Requests](/wcp_docs/xml1559763881756.html)

