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
  • Hi @thomas 

    Can you try something like this

    load(
      
      local!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"
        },
        
        local!power: index(local!engine,"Power",{}),
        index(index(local!power,"Value",{}), wherecontains("HP",apply(tostring(_),index(local!power,"Unit",{}))),{})
    )

Reply
  • Hi @thomas 

    Can you try something like this

    load(
      
      local!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"
        },
        
        local!power: index(local!engine,"Power",{}),
        index(index(local!power,"Value",{}), wherecontains("HP",apply(tostring(_),index(local!power,"Unit",{}))),{})
    )

Children

 Discussion posts and replies are publicly visible