Get value from CDT array

I'm facing an issue.

I'm calling an API that returns this response: 

 Engine: Dictionary
    Fuel: Dictionary
        Code: "100003"
        Name: "D"
        NameEx: "Diesel"
    Layout: Dictionary
        Name: "l"
    Power: List of Dictionary: 2 items
        Dictionary
            Value: "88.00"
            Unit: "KW"
        Dictionary
            Value: "120.00"
            Unit: "HP"
    Displacement: Dictionary
        Value: "1560.00"
        Unit: "ccm"
    CylindersNumber: "4"
    ValvesPerCylinder: "2"

I need to get the Power Value when Unit is equal to "HP".

I created this expression rule (and many others):

a!forEach(
  ri!Power,
  if(
    ri!Power[fv!index].Unit = "HP",
    ri!Power[fv!index].Value,
    {}
  )
)

But when I use it inside a process I get this error:

An error occurred while evaluating expression: power:rule!SBX_GetVehiclePowerValue(pv!response.eurotaxIdentificationResponse.VehicleList.Vehicle.Engine.Power) (Expression evaluation error in rule 'sbx_getvehiclepowervalue' at function a!forEach: Cannot index "Power" because it is an array type (List of SBX_Unit_Value_Type). Only fields with scalar types can be indexed from an array.) (Data Outputs)

When I test my expression rule I use this data and it works:

{
  {
    "Value": "88.00",
    "Unit": "KW"
  },
  {
    "Value": "120.00",
    "Unit": "HP"
  }
}

Any lead to resolve this issue ? Thanks !

UPDATE:

Well, it was a problem from the response I get. I had to create a rule to retrieve data from vehicle list

=load(
  a!forEach(
    items: ri!vehiculeList.Vehicle,
    expression: 
      fv!item.Engine.Power
    
  )
)

Thanks for your help !

Parents
  • Engine CDT

    Unit_Value CDT

    The API returns this:

    {
      "eurotaxIdentificationResponse": {
        "Settings": {
          "ISOcountryCode": "FR",
          "ISOlanguageCode": "FR",
          "ISOcurrencyCode": "EUR"
        },
        "VehicleList": {
          "Vehicle": [
            {
              "VehicleType": {
                "VehicleTypeCode": "10",
                "Name": "Véhicule particulier",
                "ShortName": "VP"
              },
              "Make": {
                "MakeCode": "2",
                "Name": "PEUGEOT"
              },
              "Model": {
                "ModelCode": "6640",
                "Name": "308"
              },
              "Type": {
                "NationalVehicleCode": "193363",
                "InternationalVehicleCode": "10042205023",
                "Name": "308 1.6 BlueHDi 120ch S&S BVM6 BC",
                "TrimLineName": "Active",
                "ProductionPeriod": {
                  "ProductionStartDate": {
                    "Month": "05",
                    "Year": "2017"
                  },
                  "ProductionEndDate": {
                    "Month": "10",
                    "Year": "2017"
                  }
                },
                "NewPrice": {
                  "RequestedLowerBound": "0.00",
                  "Price": {
                    "Amount": "26100.00",
                    "ISOcurrencyCode": "EUR",
                    "AmountDate": {
                      "Month": "07",
                      "Year": "2017"
                    },
                    "Indicator": "0"
                  }
                },
                "SortCode": "3020"
              },
              "MarketSegment": {
                "MarketSegmentDescription": {
                  "Code": "30004",
                  "Name": "M1"
                }
              },
              "Body": {
                "BodyStyleDescription": {
                  "Code": "10060",
                  "Name": "Ber",
                  "NameEx": "Berline"
                },
                "DoorsNumber": "5"
              },
              "Transmission": {
                "DriveType": {
                  "Code": "50001",
                  "Name": "TAV",
                  "NameEx": "Traction avant"
                },
                "GearBox": {
                  "Type": {
                    "Code": "180001",
                    "Name": "M",
                    "NameEx": "Boîte manuelle"
                  },
                  "GearsNumber": "6"
                }
              },
              "Engine": {
                "Fuel": {
                  "Code": "100003",
                  "Name": "D",
                  "NameEx": "Diesel"
                },
                "Layout": {
                  "Name": "l"
                },
                "Power": [
                  {
                    "Value": "88.00",
                    "Unit": "KW"
                  },
                  {
                    "Value": "120.00",
                    "Unit": "HP"
                  }
                ],
                "Displacement": {
                  "Value": "1560.00",
                  "Unit": "ccm"
                },
                "CylindersNumber": "4",
                "ValvesPerCylinder": "2"
              },
              "Miscellaneous": {
                "TotalWeight": {
                  "Value": "1810.00",
                  "Unit": "kg"
                },
                "PayLoad": {
                  "Value": "625.00",
                  "Unit": "kg"
                },
                "Wheelbase": {
                  "Value": "2620.00",
                  "Unit": "mm"
                },
                "Wheelbase2": {
                  "Value": "0.00",
                  "Unit": "mm"
                },
                "SeatsNumber": "5",
                "CurbWeight": {
                  "Value": "1185.00",
                  "Unit": "kg"
                },
                "ManufacturerProductID": [
                  "1PT9 A5LKD KB0 BM C0"
                ],
                "TaxHorsePower": {
                  "Value": "5.00",
                  "Unit": "HP"
                }
              }
            }
          ]
        },
        "status": "OK",
        "message": "success"
      }
    }

    I create a lot of type to parse this JSON data. I don't know if it's the right way.

Reply
  • Engine CDT

    Unit_Value CDT

    The API returns this:

    {
      "eurotaxIdentificationResponse": {
        "Settings": {
          "ISOcountryCode": "FR",
          "ISOlanguageCode": "FR",
          "ISOcurrencyCode": "EUR"
        },
        "VehicleList": {
          "Vehicle": [
            {
              "VehicleType": {
                "VehicleTypeCode": "10",
                "Name": "Véhicule particulier",
                "ShortName": "VP"
              },
              "Make": {
                "MakeCode": "2",
                "Name": "PEUGEOT"
              },
              "Model": {
                "ModelCode": "6640",
                "Name": "308"
              },
              "Type": {
                "NationalVehicleCode": "193363",
                "InternationalVehicleCode": "10042205023",
                "Name": "308 1.6 BlueHDi 120ch S&S BVM6 BC",
                "TrimLineName": "Active",
                "ProductionPeriod": {
                  "ProductionStartDate": {
                    "Month": "05",
                    "Year": "2017"
                  },
                  "ProductionEndDate": {
                    "Month": "10",
                    "Year": "2017"
                  }
                },
                "NewPrice": {
                  "RequestedLowerBound": "0.00",
                  "Price": {
                    "Amount": "26100.00",
                    "ISOcurrencyCode": "EUR",
                    "AmountDate": {
                      "Month": "07",
                      "Year": "2017"
                    },
                    "Indicator": "0"
                  }
                },
                "SortCode": "3020"
              },
              "MarketSegment": {
                "MarketSegmentDescription": {
                  "Code": "30004",
                  "Name": "M1"
                }
              },
              "Body": {
                "BodyStyleDescription": {
                  "Code": "10060",
                  "Name": "Ber",
                  "NameEx": "Berline"
                },
                "DoorsNumber": "5"
              },
              "Transmission": {
                "DriveType": {
                  "Code": "50001",
                  "Name": "TAV",
                  "NameEx": "Traction avant"
                },
                "GearBox": {
                  "Type": {
                    "Code": "180001",
                    "Name": "M",
                    "NameEx": "Boîte manuelle"
                  },
                  "GearsNumber": "6"
                }
              },
              "Engine": {
                "Fuel": {
                  "Code": "100003",
                  "Name": "D",
                  "NameEx": "Diesel"
                },
                "Layout": {
                  "Name": "l"
                },
                "Power": [
                  {
                    "Value": "88.00",
                    "Unit": "KW"
                  },
                  {
                    "Value": "120.00",
                    "Unit": "HP"
                  }
                ],
                "Displacement": {
                  "Value": "1560.00",
                  "Unit": "ccm"
                },
                "CylindersNumber": "4",
                "ValvesPerCylinder": "2"
              },
              "Miscellaneous": {
                "TotalWeight": {
                  "Value": "1810.00",
                  "Unit": "kg"
                },
                "PayLoad": {
                  "Value": "625.00",
                  "Unit": "kg"
                },
                "Wheelbase": {
                  "Value": "2620.00",
                  "Unit": "mm"
                },
                "Wheelbase2": {
                  "Value": "0.00",
                  "Unit": "mm"
                },
                "SeatsNumber": "5",
                "CurbWeight": {
                  "Value": "1185.00",
                  "Unit": "kg"
                },
                "ManufacturerProductID": [
                  "1PT9 A5LKD KB0 BM C0"
                ],
                "TaxHorsePower": {
                  "Value": "5.00",
                  "Unit": "HP"
                }
              }
            }
          ]
        },
        "status": "OK",
        "message": "success"
      }
    }

    I create a lot of type to parse this JSON data. I don't know if it's the right way.

Children
No Data

 Discussion posts and replies are publicly visible