Skip to main content
swapnar6405
April 12, 2023
Solved

Code not behaving same when I used localVariable with fixed number, expressionrule

  • April 12, 2023
  • 9 replies
  • 0 views

Hi Experts,

Below Block-A code line is working fine, whereas Block-B is not working even though "tointeger(index(rule!AB_getReviewKey(key: 100),"reviewkey",null()))" is returned 2.

Any comments please.

----------------------- Block-A -------------------------

a!localVariables(
local!reviewkey: 2,
local!excludeKeys: if(
local!reviewkey = 2,
{ 1, 3, 4},
if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
),
local!excludeKeys
)

----------------------- Block-B -------------------------

a!localVariables(
local!reviewkey: tointeger(index(rule!AB_getReviewKey(key: 100),"reviewkey",null())),
local!excludeKeys: if(
local!reviewkey = 2,
{ 1, 3, 4},
if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
),
local!excludeKeys
)

Best answer by mikes0011

You should amend rule!AB_getReviewKey to return a single item if the expected output is always single.  If it isn't, then you should use square brackets or index() when calling it in order to get a single value into your local variable.

Also, when posting code snippets (even short ones like this) please use a Code Box and make sure to paste indented code - it makes it much easier to read / mentally process for us.

a!localVariables(
  local!reviewkey: tointeger(
    index(  /* use index() to get an index (1) */
      property(rule!AB_getReviewKey(key: 100), "reviewkey", null()), /* use property() to get a property (.reviewKey) */
      1,
      null()
    )
  ),
  local!excludeKeys: if(
    local!reviewkey = 2,
    { 1, 3, 4},
    if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
  ),
  
  local!excludeKeys
)

9 replies

April 13, 2023

Are you sure

tointeger(index(rule!AB_getReviewKey(key: 100),"reviewkey",null()))
 is returning 2? If this rule is a QE or QR then I can't see you are indexing "data" from it first (or you may have indexed it in the rule itself). Cannot say much, code looks fine.

swapnar6405
April 13, 2023

If I pass 2 or 5, I am able to see the local!excludeKeys with required array o/p, whereas when I use the expression rule it is not working.

In my expression rule I am using .data at the end and when it test I was getting integer output only.

Is some thing wrong with my any type conversion here.

amans0009
April 13, 2023

Can you please provide us with more info like the error message or something like output so that so that we can tell what wrong is going on.

swapnar6405
April 13, 2023

In the first, second screen shots I am getting the required o/p where as in last screen shot, instead of getting an array o/p, I am just getting 1 as an o/p and which is of type List of Number (integer).

a!localVariables(
local!reviewkey: 2,
local!excludeKeys: if(
local!reviewkey = 2,
{ 1, 3, 4},
if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
),
local!excludeKeys
)

o/p: 

-------------------

a!localVariables(
local!reviewkey: 5,
local!excludeKeys: if(
local!reviewkey = 2,
{ 1, 3, 4},
if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
),
local!excludeKeys
)

o/p: 

----------------------

a!localVariables(
local!reviewkey: tointeger(index(rule!AB_getReviewKey(key: 100),"reviewkey",null())),
local!excludeKeys: if(
local!reviewkey = 2,
{ 1, 3, 4},
if(local!reviewkey = 5, { 1,3,4,5,6 }, {1,2,3 })
),
local!excludeKeys

)

O/P:

stefanhelzle0001
Brainy
April 13, 2023

Could it be that "local!reviewkey" is a list of integers in your last example?