I have a List of Data of type CDT, i wanted to convert that into List of varient to use that data in A!forEach() ???
Discussion posts and replies are publicly visible
Here is probably our missing piece - your Excel data is coming in not as typed data, but rather an array of arrays of type text. This is why "fv!item[3]", and similar, is giving you a working result.
Given this, your original code appears like it might not be as far off-base as I'd assumed. What particular error message do you get when you try to execute the expression rule as originally written?
Also: can you confirm which Appian version you're currently using?
You are correct it is array of arrays of type text.from excel.
My Appian Verison is 20.3
I think I need to use something other than a! update as mentioned by u previously.
" Note: if you're not yet in 21.2, a!update() will not be available but you can simply use updateDictionary() which is available in a plug-in. "
What is the exact error you're getting when you run the code you posted originally?
What happens when you run the attached expression instead? For temporary debugging I've swapped out the "read from excel" text list results with an array of JSON strings (Appian refuses to recreate a "array of text string arrays" otherwise by any other method I know of). But other than the JSON conversion it should be analogous to your version. The following worked for me (though I did have to swap out the type! call and just wrap the results in a plain dictionary) --
a!localVariables( local!dataInput: { a!toJson({ "pfizer", "100", "2", "200" }), a!toJson({ "cipla", "120", "3", "250" }) }, local!finalUpdate: a!forEach( items: local!dataInput, expression: a!localVariables( local!checking: "cipla", local!testItem: a!fromJson(fv!item), 'type!{urn:com:appian:types:mb}MB_Medicine__Cost_Data_fromExcel'( name: if(local!testItem[1] = local!checking, "ciplex", local!testItem[1]), perCost: local!testItem[2], quantity: local!testItem[3], totalCost: local!testItem[4] ) ) ), local!finalUpdate )
If you're calling the expression rule on the CDT coming from the process variable, it will no longer be giving you the "array of text arrays" like in the original example, and therefore the code won't work for the reasons I mentioned in my original reply. You're mixing up 2 pieces of functionality that work in 2 separate ways.
Yeah can you show what the current value of pv!MedicineData is? I assume that process variable is empty because it couldn't be cast from your original value to that type. You probably need a step of casting the result from the excel sheet to that type first, and then using Mike's original response.