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
7 subscribers
Views
2772 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
How do I determine if a column name exists in an array or datasubset?
jayanthik
over 8 years ago
How do I determine if a column name exists in an array or datasubset?
Say for example, the below expression when executed returns that datasubset has two fields /columns names - firstName and secondName. I want to find out if any string "xyz" is present as a field or column in a datasubset /array.
todatasubset({
type!Column(field: "username", alias: "un", visible: true),
type!Column(field: "firstName", alias: "first", visible: false),
type!Column(field: "lastName", alias: "last", visible: true)
},
a!pagingInfo(startIndex: 1, batchSize: 2, sort:{field: "alias", ascending: true})
)
.data
when executed returns the below result
[field=firstName, alias=first, visible=false], [field=lastName, alias=last, visible=true]
OriginalPostID-152071
OriginalPostID-152071
Discussion posts and replies are publicly visible
0
vineeta6579
over 8 years ago
You can store the result of the todatasuset into the local variable & print the same variable on the screen. It will list the detail info of it.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
nathan.schmitz
Certified Associate Developer
over 8 years ago
If I understand your question, I think comparing index( local!varName , "xyz" , null() ) to null() might help.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
judyg
over 8 years ago
What about using fn!contains(array, value)? See the below test code.
= load(
local!datasubset: todatasubset(
{
type!Column(
field: "username",
alias: "un",
visible: true
),
type!Column(
field: "firstName",
alias: "first",
visible: false
),
type!Column(
field: "lastName",
alias: "last",
visible: true
)
},
a!pagingInfo(
startIndex: 1,
batchSize: -1,
sort: {
field: "alias",
ascending: false
}
)
).data,
{
a!textField(
label: "Test column exists or not",
value: if(fn!contains(local!datasubset.field,"lastName"),
"The column exists",
"The column is missing"),
readOnly: true
),
a!textField(
label: "all columns",
value: local!datasubset.field,
readOnly: true
)
}
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
judyg
over 8 years ago
I think you might want to know how to check if a datasubset contains a column to show on the screen. Since you set batch size is 2, so only 2 columns will be shown. If so, you can do it in the following way.
= load(
local!datasubset: todatasubset(
{
type!Column(
field: "username",
alias: "un",
visible: true
),
type!Column(
field: "firstName",
alias: "first",
visible: false
),
type!Column(
field: "lastName",
alias: "last",
visible: true
)
},
a!pagingInfo(
startIndex: 1,
batchSize: 2,
sort: {
field: "alias",
ascending: true
}
)
).data,
local!displayColumns: local!datasubset,
{
a!textField(
label: "Test column exists or not",
value: if(
fn!contains(
local!displayColumns.field,
"username"
),
"The column exists",
"The column is missing"
),
readOnly: true
),
a!textField(
label: "all columns",
value: local!datasubset.field,
readOnly: true
)
}
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
PhilB
Certified Lead Developer
over 8 years ago
You may wish to include an index to handle null data subsets:
if(
fn!contains(
index(
local!displayColumns
"field",
{}
)
"username"
),
"The column exists",
"The column is missing"
),
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel