Need to understand how this rule is defined in the attachment. Does the item[ ]

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

Parents
  • 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.
Reply
  • 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.
Children
No Data