Hi,
I'm trying to save into a local variable some data retrieved from an ER. But I would need to update some fields before to store it into my new local var.
Is there any way to do it ?
With the code below I can either cast the data, either create a new CDT local var with the new field value, but I did not succeed to do both.
(as my CDT could contain more than 50 fields I do not want to override all theses 50 fields in the code below).
a!localVariables( local!vehicle: rule!TST_GetVehiclesWithFilters( id: 1 ).data, local!vehicleCast: cast('type!{urn:com:appian:types:tst}TST_Vehicles', local!vehicle), local!vehicleUpdate: 'type!{urn:com:appian:types:tst}TST_Vehicles'( make: "New Make" ), { local!vehicleCast, local!vehicleUpdate } )
Example : my initial data retreived by the ER is :
TST_Vehicles :
and I would like my transformed data like this :
TST_Vehicles
Discussion posts and replies are publicly visible
This plugin should help
community.appian.com/.../cdt-manipulation
Thank you Stefan but I've already tested it without success.
Am I forgetting something ? (the value of the "make" field does not change)
a!localVariables( local!vehicle: rule!TST_GetVehiclesWithFilters( id: 1 ), local!vehicleUpdateCDT: updatedictionary( dictionary: local!vehicle, fieldsAndValues: ( { make: "test2" } ) ), { local!vehicleUpdateCDT } )
Lines 7-10 should look like
fieldsAndValues: { make: "test2" }
There are to many brackets.
I've already used this plugin with this ({ }), and it has worked well.
But in my below ER example, it still does not work (according your suggestion).
Would you see another error ?
a!localVariables( local!item: rule!SBA_QR_GetConfigurationItemByIdent(1), updatedictionary( local!item, { name: "Hans" } ) )
My small test. Works a expected for dictionaries, maps and CDTs. How does your CDT look like? There are some quirks with certain data type.
My test CDT contains standard data types :
a!localVariables( local!item: {name: "NOT HANS"}, updatedictionary( local!item, { name: "HANS" } ) )
Does this work for you?
yes, this works fine.
In this code of yours
What is the actual content of local!vehicle? Datasubset / single item / list of items?
It contains a only one item DataSubset :
List of DataSubset - 1 item
OK. Then you need to drill down like local!vehicle.data[1].
Very good Idea, I did not think about this :-(
but it still does not work :
a!localVariables( local!vehicle: rule!TST_GetVehiclesWithFilters( id: 1 ).data[1], local!vehicleUpdateCDT: updatedictionary( dictionary: local!vehicle, /* "cdt" atribute works well too */ fieldsAndValues: { make: "test2" } ), local!vehicle /* sorry variable was incorrect --> local!vehicleUpdateCDT! */ )
Here is the result:
Dictionary
you're using "updatedictionary()" but then passing it a property named "cdt" instead of "dictionary". This would cause it to assume that the input dictionaryis blank, which is approximately what we're seeing from your output.
Sorry Mike, it was an error, of course, I've tested before with the "dictionary" field name.
I have edited my previous post.
oh, also - at the end of your example code you're only outputting the value of local!vehicle, not of local!vehicleUpdateCdt - so we would expect the output you're seeing to only be the original and not the updated version.
Instead your code should look like this:
a!localVariables( local!vehicle: rule!TST_GetVehiclesWithFilters( id: 1 ).data[1], local!vehicleUpdateCDT: updatedictionary( dictionary: local!vehicle, fieldsAndValues: { make: "test2" } ), local!vehicleUpdateCDT )
I'm re-sorry Mike, my previous post was sent too quickly (I've re-edited my previous post).
Thank you, all works fine, but I confirm you that the old "cdt" attribute works well, anyway I have to use the new one.
Stefan, thank you very much for your help. "data[1]" saved my life ;-)
- A last question, if you would not have this plugin, how would you do ?
you would enter the 50 fields of the CDT and update the only one value to change ?
Using the plugin is the way to go. I am talking to Appian for quite a while to get this function into the product. There is no environment I have ever seen where this is not deployed. In the end, this is what plugins are for and it works pretty well.