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
+1
person also asked this
people also asked this
Replies
7 replies
Subscribers
9 subscribers
Views
3352 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Need to understand how this rule is defined in the attachment. Does the item[ ]
nikhilh0001
over 10 years ago
Need to understand how this rule is defined in the attachment. Does the item[ ] refer to ri!item or is it some array object?
OriginalPostID-146357
OriginalPostID-146357
Discussion posts and replies are publicly visible
0
chetany
A Score Level 1
over 10 years ago
Hi Nikhil, from screenshot: rule!CASE_APP_random(length(ri!item)) is some rule which is returning(expected to return) a integer. This integer will be used to index into the item. So, item is an array.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 10 years ago
item can also be a dictionary like item = [firstname: "ABC", lastName: "XYZ"] . In that case, the rule rule!CASE_APP_random is expected to return a property.(in this example "firstName" or "lastName")
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
nikhilh0001
over 10 years ago
Thanks Chetan...
so when I tried using typename(typeof(item[...])), it returned text and not a list.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 10 years ago
I just imported the case managment App form forum. I also checked that rule. It is confusing since there is rule input item, ri!item and also just item used like an array name.. Not sure yet
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
chetany
A Score Level 1
over 10 years ago
Hi, I found how the rule works. In The item[], the item is the same as rule input. Now copy paste the below code into interface designer(just for verifying..)
Please define a rule input called 'item' with Any Type.
a!dashboardLayout(
firstColumnContents: {
a!textField(
label: "Test",
value: rule!CASE_APP_randomItemFromArray(item: ri!item)
)
}
)
To Test it out, let us assume you have employee cdt and DS with some fields in employee cdt like id, fname and lname. Also assume that you have a query rules like getEmployeeById(id) which returns the specific employee based on id. I am assuming you have atleast 5 records of employee in DS.
Now Test this rule in interface designer. While gving the input in interface designer, give the input like this: {getEmployeeByid(1), getEmployeeByid(2), getEmployeeByid(3)}
Each time you execute/test this rule, you will get a different output. In short, the above rule just takes an array of "items", where items can be any type of CDT.(might be something other than employee, this is just an example.). This rule then selects a random 'item' i.e random CDT from the input array and returns it.
Now, the same rule definition in screenshot can be rewritten as :
=ri!item[rule!CASE_APP_random(length(ri!item))] instead of
=item[rule!CASE_APP_random(length(ri!item))]
It does not change the meaning. It just returns a random cdt from the passed array of cdts.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Mike Schmitt
Certified Lead Developer
over 10 years ago
The answer to your original question, I think, is Yes - the first instance of "item" should actually be called as "ri!item" in the rule. But i think it'll work without that, confusion aside.
The simplest way to demonstrate this rule would be to call it from another expression rule. Since ri!item is of "Any Type" type, you can't actually force in an array when you use the "Test" functionality in the expression editor. But if you create a new / unsaved expression, you can pass in an array. Such as:
rule!CASE_APP_randomItemFromArray(
{ "first", "second", "third", "fourth" }
)
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
malcolm.ross
Appian Employee
over 9 years ago
Pardon the confusion.. I actually wrote this rule.. It was designed to be used in the data loader for the Case Management Framework.. The rule input of "item" is designed to take in an array of any type and randomly return an item from the array.. We didn't expect it to be one of the common components designers would re-use.. but if you are, I'd love to hear your use case.
This was designed for use in the Order Generator Data Loader and Service Request Data Loader in the Case Management Framework specifically..
As you noticed, rule inputs may also be referenced by name directly.. without the ri! in an expression rule..
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel