Hi Team,
I have list of dict. like:
{{{customername: "Hardy", name: "S1", region: "Asia"}}, {{customername: "Len",name: "SRD", region: "NA"}}, {{customername: "MAdusa", name: "Line 9", region: "Australia"}}}
Now I want to store only name values in a local variable.
I need result like, '
local!variable1 = { "S1","SRD","Line 9" }
how to do this with loop ?
Because list of dict. can be more or less or empty so need code which can handle if the list comes empty(can return null), I will be using this code in expression rule
Discussion posts and replies are publicly visible
The simplest way that works in most cases is to just access the dot property, i.e. "local!myList.customerName", which is NOT null-safe; the null-safe alternative is the Property() function - i.e. "property(local!myList, "customerName", {})", which returns an empty set as a default if the list is empty or no such property is found.
a!localVariables( local!list: { { customername: "Hardy", name: "S1", region: "Asia" }, { customername: "Len", name: "SRD", region: "NA" }, { customername: "MAdusa", name: "Line 9", region: "Australia" } }, local!emptyList: {}, "Customer Names (populated list): " & property(local!list, "customername", {}) & char(10) & char(10) & "Customer Names (empty list): " & property(local!emptyList, "customername", {}) )
I tried but it works on list of dict. but not on my type i.e
In this case it still works for me:
However the problem with a list of arbitrary dictionaries, as opposed to an array of the same dictionary, is if there are different properties in the different dictionaries, the system will start behaving weirdly in my experience. But as long as there's a property with a name matching exactly what you pass into the property() function, it should be resilient enough to work. Note in this case the property name is case sensitive.
In this example I've toyed with the property names but the property() function still produces the expected results (as long as we observe the case sensitivity caveat).
I managed to get this array, {{"S1"}, {"SRD"}, {"Line 9"}}
How to get { "S1","SRD","Line 9" } in this form dynamically and with null result if array is empty
Please share the code you're using to return that result.
Also if you could provide some more information about your use case and/or the data set you're getting and why, that would be helpful - for instance, why is your initial data set a list of list of dictionaries?
Agreed with Mike that seeing your data would be helpful, but I'll also say that a!flatten() is your friend when you have highly nested dictionaries - it can often remove extra unnecessary layers.