Skip to main content
April 9, 2024
Solved

Merging a map and a dictionary

  • April 9, 2024
  • 6 replies
  • 0 views

I have a map and a dictionary.. How can I merge them and save the output to a datasubset?

    Best answer by davidj137213

    IN case is a list of dict...

    a!localVariables(
      local!dict: {({x: 1, y: 2}), ({x: 3, y: 4})},
      local!map: a!map(item: 1, value: "PRueba"),
    
    
      todatasubset(union(cast( a!listType(type!Map), local!dict), local!map))
    
    
    
    
    )

    6 replies

    davidj137213
    Brainy
    April 9, 2024

    a!localVariables(
      local!dict: ({x: 1, y: 2}),
      local!map: a!map(item: 1, value: "PRueba"),
      
      
      todatasubset(union(cast(type!Map, local!dict), local!map))
      
      
      
      
    )

    April 9, 2024

    [mention:04c48a6a061f4609acd71aebfc4be9ad:e9ed411860ed4f2ba0265705b8793d05]  if the dictionary is list? 

    Im getting below error with above example

    CastInvalidCould not cast from List of Dictionary to Map. Details: CastInvalid

    davidj137213
    Brainy
    April 9, 2024

    Are you using my code? Which version are you using? If not, please share it...

    peter.lewis
    Employee
    April 9, 2024

    In general I would recommend always casting a dictionary to a map (or even constructing a map from the beginning) rather than using a dictionary. Since maps are strongly typed, they're generally easier to index data and work with in your applications [emoticon:c4563cd7d5574777a71c318021cbbcc8]