Skip to main content
Known Participant
Dec 27, 2024 9:21 AM UTC
Question

How to convert List of Varients to List of Dictionary

I have a usecase where there are two arrays : one is empty and second one has some values

Array1 : {"",""},

Array2 : {1:1,2:2}

After removing null or empty values from Array1 using filter function filter(a!isNotNullorEmpty,Array1), I have got empty array which is of List of Varient type

Now I want to apply difference function difference(Array1,Array2)

Since both are different data types, im being thrown error as invalid types.

If I have any values in Array1 like {1:1}, it would be of type List of Dictionary, but now here it is List of Varient since nothing there in the Array.

How can I perform difference function operation now? Is there any workaround to convert list of varient to list of dictionary ?

10 replies

stefanhelzle0001
Brainy
Dec 27, 2024 10:37 AM UTC

Something like this should do it.

cast(, a!listType(type!Dictionary))

Known Participant
Dec 27, 2024 10:50 AM UTC

I tried this but it dint work.
Array1 : List of Variant 
Assuming list of dictionaries
Array2 is explicitly List of dictionaries

I gave cast(array1,a!listType(recordtype))

babyjamus959688
New Participant
Dec 27, 2024 10:52 AM UTC

I think that was small syntax error, try this one.

a!localVariables(
local!array1: {},
local!array2: { i: 1, j: 2 },
cast(typeof({ local!array2 }), local!array1),
)

babyjamus959688
New Participant
Dec 27, 2024 10:38 AM UTC

First of all, difference function is to return the values which is present in array 1 and not in array 2. Since first array is empty no need to call difference function itself. So do null check and if both array 1 and array 2 have values call difference function else return array 1.

Known Participant
Dec 27, 2024 10:40 AM UTC

thats just a usecase not the original one. You cannot know its type and value in runtime as I have given it as Anytype.

babyjamus959688
New Participant
Dec 27, 2024 10:58 AM UTC

we can always do null check for the arrays before using the difference function as the null check doesn't bother type of a variable.