Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
+2
person also asked this
people also asked this
Replies
19 replies
Subscribers
10 subscribers
Views
18116 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
General
Is there a way to *dynamically* add a new element to a dictionary?
briank538
over 7 years ago
I'd like to at run time add new name value pair to a dictionary. Is this possible?
Thanks.
OriginalPostID-239395
Discussion posts and replies are publicly visible
Top Replies
Stefan Helzle
over 3 years ago
in reply to
paulg0001
+2
A Score Level 3
Why is an update no option? The new version includes to old functions as well. This is a quick solution. I am pretty sure there is a better one. a!localVariables( local!values: {{ id:1, name:"alpha…
0
Nagashankar Nallavalli
over 7 years ago
@ briank please find the below link
forum.appian.com/.../Expressions.html
hope this is helpful to you
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shashank
over 7 years ago
@briank Hi , did you have a chance to look at the following shared component
https://forum.appian.com/suite/tempo/records/item/lMBCLGOdlMUpdGVqW3dQaIKmclBmvvNEj8vu_cjb7T-5YiPr4Fu8ly5Yj1s09uenE4RYzA8zKyx7eiUhu-iLnNiL_yNHr1dalWMFghiqrZpWgaUrg/view/summary
Please have a look at the updatecdt , it might be helpful in adding a new field to your cdt
Thanks
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shashank
over 7 years ago
Did a small test , not sure how far it may be helpful , but might be a start :
with(
local!test : {{id : 1, name : "test"}},
local!updated : updatecdt(local!test,{newField : "myNew"}),
local!updated
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
The problem is that updatecdt does not allow dynamic field names. But if you add
a!fromJson(substitute(a!toJson({tzqYx62_01_:ri!value}), "tzqYx62_01_", ri!key))
to the above code, even that is possible. It creates a dictionary with a fixed field name and converts it to JSON. Then it replaces the field name in the JSON string to the desired field name and converts it back to an Appian dictionary.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
kondetiv
over 7 years ago
here is the small code snippet i tried. Not sure how far it may be helpful for you.
with(
local!dictionary:{{label:"firstName",value:"kondeti"}},
{
append(local!dictionary,{label:"lastName",value:"venkat"}),
}
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
kondetiv
over 7 years ago
output for the above code :-
type List of Dictionary
2 items
Value
[label:firstName,value:kondeti]; [label:lastName,value:venkat]
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
kondetiv
over 7 years ago
sorry misunderstood !
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shashank
over 7 years ago
@stefanh , Thanks a lot for your valuable input , I have updated the above code with your snippet . It worked like a charm !!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Shashank
over 7 years ago
with(
local!test: {
{
id: 1,
name: "test"
}
},
local!newKeyValPair: a!fromJson(
substitute(
a!toJson(
{
tzqYx62_01_: ri!value
}
),
"tzqYx62_01_",
ri!key
)
),
local!updated: updatecdt(
local!test,
local!newKeyValPair
),
local!updated
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 7 years ago
You are welcome :-)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
>