issue with reject(fn!isnull, 'array of arrays') function on a data generated from an expression rule

 Hi Community,

I have a strange problem with the reject function. I am getting an error when I work with the data generated with my expression rule. If I do a copy & paste of the data generated, the function does not give me an error but I am not getting what I expected.

A further description of the problem (as maybe I am just taking the wrong approach), I have on CDT on which one of the values is the id's of another CDT. I wanted to count how many times the second CDT is used, so I can have a graphical representation in a form of a pie chart. My expression rule gives returns the data in a way that is easy to work on graphs, like the pie chart below. 

When I call the expression rule, I get the data like this:

{{}, {}, {}, {}, {}, {}, {}, {}, {"Outbound", 1}, {}, {"Mudcakes", 2}, {"Happy Industries", 2}, {}, {}}

 Which means that "Outbound" appears 1, "Mudcakes" 2 and "Happy Industries" 2

On the pie chart, the values "{}" appears like [Series 1], [Series 2] and so on. I want to get rid of those empty arrays.

Then, I try to use the function reject, like below

reject(fn!isnull,rule!APP_myExpresionRule), it troughs me an error

Expression evaluation error at function 'reject': Incorrect number of parameters for function; expected 1 parameters, but found 0 parameters

Now, when I copy the data generated with rule!APP_myExpresionRule, 

reject(fn!isnull,{{}, {}, {}, {}, {}, {}, {}, {}, {"Outbound", 1}, {}, {"Mudcakes", 2}, {"Happy Industries", 2}, {}, {}})

I get this:

 {"Outbound", 1, "Mudcakes", 2, "Happy Industries", 2}
 
which is not what I am looking for, as I would expect to have something more like this:
i
{{"Outbound", 1},{"Mudcakes", 2}, {"Happy Industries", 2}}
 
Below the pie chart as it looks now:

 

 

Any suggestions?

 

Thanks!

Manuel

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer
    It appears that Reject is flattening the resulting array prior to evaluating. This isn't much of a surprise to me, since Appian's ability to handle array-of-arrays in most cases is pretty spotty (and slightly unpredictable). I would suggest you consider making your expression rule pass back dictionary data instead of {text, integer} arrays, because then you could pretty easily weed out blank/empty entries from your return list without needing to bend over backwards to avoid the array flattening that's happening here.
  • Thank you very much, that way worked for the reject function!

    first I store on a local variable and call:    local!aux.data

    Then I get:

    {null, null, null, null, null, null, null, null, {name: "Outbound", count: 1}, null, {name: "Mudcakes", count: 2}, {name: "Happy Industries", count: 2}, null, null}

    Now I can call reject() :     reject(fn!isnull,local!aux.data)

    And then I get:

     {{name: "Outbound", count: 1}, {name: "Mudcakes", count: 2}, {name: "Happy Industries", count: 2}}
     
    So the pie chart looks as I wanted to:
     
     
    Thank you!

     

     

     

     

Reply
  • Thank you very much, that way worked for the reject function!

    first I store on a local variable and call:    local!aux.data

    Then I get:

    {null, null, null, null, null, null, null, null, {name: "Outbound", count: 1}, null, {name: "Mudcakes", count: 2}, {name: "Happy Industries", count: 2}, null, null}

    Now I can call reject() :     reject(fn!isnull,local!aux.data)

    And then I get:

     {{name: "Outbound", count: 1}, {name: "Mudcakes", count: 2}, {name: "Happy Industries", count: 2}}
     
    So the pie chart looks as I wanted to:
     
     
    Thank you!

     

     

     

     

Children
No Data