Group By a field with a DataRaptor Transform

data-raptorjsonomniscriptomnistudio

I'm attempting to group Quote Lines in the JSON output of a DataRaptor Extract with a Transform and am unsure if this is possible without an Integration Procedure.

I currently have Quote Lines outputting as such:

    "QuoteLine": [
    {
      "ProductSiteName": "BO1",
      "ProductId": "Prod1",
      "Quantity": 1,
      "Number": 1,
      "Quote": "a5LQL0000001k8r2AA"
    },
    {
      "ProductSiteName: "S0-1",
      "ProductId": "Prod2",
      "Quantity": 15,
      "Number": 2,
      "Quote": "a5LQL0000001k8r2AA"
    } ...

and would like to transform that to group based on the ProductSiteName as such:

    "Site" : [
    {
      "ProductSiteName": "BO1"
      "QuoteLine": [
      {
        "ProductId": "Prod1",
        "Quantity": 1,
        "Number": 1,
        "Quote": "a5LQL0000001k8r2AA"
      }
    },
    {
      "ProductSiteName": "S0-1",
      "QuoteLine": [
      {
        "ProductId": "Prod2",
        "Quantity": 15,
        "Number": 2,
        "Quote": "a5LQL0000001k8r2AA"
      }
    } ...

I'm relatively new to OmniScripts and feel like I might be already incorrect at the Extract level.

Best Answer

You will need to use an Integration Procedure to accomplish the required transformation.

High level steps are:

  1. Extract all Quote Lines
  2. Use a Dataraptor Transform to extract unique values for ProductSiteName.

This can be done by passing in the Quoteline list to the DR Transform, using the formula LISTMERGE("ProductSiteName",LIST(%QuoteLine%)) to "extract" the unique ProductSiteName values and then let the DR Transform return a list of all the unique ProductSiteName values:

enter image description here enter image description here

The output will look like:

[
  {
    "ProductSiteName": "BO1"
  },
  {
    "ProductSiteName": "S0-1"
  }
]
  1. Loop over these values using a Loop Block:

    1. Create another Integration Procedure that accepts a ProductSiteName value as well as the list of Quote Lines
    2. Use a List Action to Extract all Quote Lines for the given ProductSiteName
    3. Use the Response Action to return the JSON for a given ProductSiteName in the required format:
{
  "ProductSiteName": "S0-1",
  "QuoteLine": [
  {
    "ProductId": "Prod2",
    "Quantity": 15,
    "Number": 2,
    "Quote": "a5LQL0000001k8r2AA"
  }
}
  1. In the Parent Integration Procedure build the final output from the Loop Block and return it using a Response Action.

Good luck!

Related Topic