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
Replies
5 replies
Subscribers
8 subscribers
Views
1834 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Hi, I'm having a few issues getting an expression which can obtain data from
jarrods229
over 10 years ago
Hi, I'm having a few issues getting an expression which can obtain data from a 2nd tier of nested objects.
Essentially I have a collection of "Parents" where the data for children can be described using ad-hoc data structure as:
= {
{
ParentName: "Amanda",
children: {
{
Child: {
ChildName: "Emma"
}
},
{
Child: {
ChildName: "Abi"
}
}
}
},
{
ParentName: "Kyle",
children: {
{
Child: {
ChildName: "Ethan"
}
}
}
}
}
What I'm after is an array of text values for all the ChildNames - but I can't seem to make use of the apply, merge or union functions to achieve this. Any Ideas?...
OriginalPostID-124332
OriginalPostID-124332
Discussion posts and replies are publicly visible
0
Michael Chirlin
Appian Employee
over 10 years ago
Jarrod,
Try using the index function, for your example above it would look like this:
index(index(index(index(local!data, 1,""), "children", ""), "Child", ""), "ChildName"))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Michael Chirlin
Appian Employee
over 10 years ago
Here is an example you can try in the expression editor:
with(
local!data: {
{
ParentName: "Amanda",
children: {
{
Child: {
ChildName: "Emma"
}
},
{
Child: {
ChildName: "Abi"
}
}
}
},
{
ParentName: "Kyle",
children: {
{
Child: {
ChildName: "Ethan"
}
}
}
}
},
index(index(index(index(local!data, 1,""), "children", ""), "Child", ""), "ChildName")
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
jarrods229
over 10 years ago
Thats only returning Emma and Abi, its not picking up Ethan from the second parent in the collection - I was hoping to get Emma, Abi, Ethan returned as the one collection.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Michael Chirlin
Appian Employee
over 10 years ago
To do that you will need two rules. The inner rule will put out the child names from each parent and the outer rule will apply that inner rule to each parent. It will look like this:
***PARENT RULE***
with(
local!data: {
{
ParentName: "Amanda",
children: {
{
Child: {
ChildName: "Emma"
}
},
{
Child: {
ChildName: "Abi"
}
}
}
},
{
ParentName: "Kyle",
children: {
{
Child: {
ChildName: "Ethan"
}
}
}
}
},
apply(
rule!Child_Rule,
enumerate(length(local!data)) + 1,
local!data
)
)
***CHILD RULE***
Inputs:
index (int)
data (any type)
index(index(index(index(ri!data, ri!index,""), "children", ""), "Child", ""), "ChildName")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
jarrods229
over 10 years ago
ok great thats working, thanks for your help Michael!
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel