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
8 replies
Subscribers
7 subscribers
Views
3219 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Unexpected behavior of fn!displayvalue() in combination with fn!error()
chetany
A Score Level 1
over 7 years ago
I observed that if you use fn!error() in the defaultValue of the fn!displayvalue() function, the fn!displayvalue() behaves different.
It always returns the error message, even if we have a match in the array and replacementarray
Eg:
with(
local!num: 1,
fn!displayvalue(
local!num,
{2,1,3,4},
{"Num2", "Num1", "Num3", "Num4"},
fn!error("default value should not be evaluated")
)
)
In the code snippet, as per the usual behavior of displayvalue(), the expected output is "Num1". But, instead it returns the error message - it means the default value gets evaluated even if we have a match - and it is returned. I believe the fn!error() functions behaves like a Java Exception or Error.
But, lets take another example of using fn!if() with fn!error()
if(3>2, "Correct", fn!error("Not Correct"))
This returns "Co...
OriginalPostID-236519
Discussion posts and replies are publicly visible
0
chetany
A Score Level 1
over 7 years ago
...rrect" - which is the expected output.
I think the behavior of fn!error() is not consistent - if we compare if() and displayvalue()
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
nikhilj
over 7 years ago
fn!error is used as default value in displayvalue function and probably because it is used as a value it gets evaluated to generate the value thus giving error every time.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
kondetiv
over 7 years ago
As you said, yes fn!error("Not Correct") will not work with fn!displayvalue(). The default value could be Any Type. In this case use some number as default value. Below code works fine.
with(
local!num: 15,
fn!displayvalue(
local!num,
{2,1,3,4},
{1, 2, 3, 4},
23
)
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
@kondetiv, I agree with you that we can use a number as a default value. I am aware of the usual usage.
However, I was thinking if we can throw an error if none of the values match using the fn!error() function in the default value.
As per my observation, the behavior of displayvalue() is different with fn!error() and hence I was surprised.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
From the documentation of error() function on forum, - "This function is used for invalidating execution. It never returns a value."
So, maybe that is the reason why it behaves different when used with if() versus displayvalue()
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
I think what is happening is Appian is trying to cast your default value to whatever type "inArray" is ahead of time. I'm guessing that trying to cast "error("some error")" just triggers the error
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 7 years ago
@joshl, you are right - but just a small correction, I think it is trying to cast to the type of "replacement"
Try fn!displayvalue(9, {1,2,3},{"hello", "bye"}, true )
In the output, you get true - but its not Boolean or Number, it is Text.
So, we can conclude that default value gets cast to the type of "replacement". I also tried fn!displayvalue(9, {1,2,3},{4.5,8.9,6.7}, true ).
It returned 1 (Number-Decimal).
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Josh
Certified Lead Developer
over 7 years ago
Ah yeah you are right I got mixed up. "value" gets casted to "inArray" type not "default"
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel