Dynamic Tab expression rule

Certified Associate Developer

So I am trying to have a dynamic page name depending on the number of tasks being displayed in grids. I have set up an if() statement for the page view name and I have the expression rule set up as:

a!queryProcessAnalytics(report: cons!report,
contextProcessModels: rule!ContextProcessModels(),
query: a!query(
                     pagingInfo: local!pagingInfo,
                     logicalExpression: a!queryLogicalExpression(
                                                         operator: "OR",
                                                          filters: {
                                                                     a!queryFilter(
                                                                                     field: "c8",
                                                                                     operator: "=",
                                                                                      value: ri!orderId,),},),),

).totalCount,
{local!Variable}))

orderId is a rule input and its a integer type, when the code is run, it will give the correct values but other times it gives a value that is too high. I tried doing length(union(local!Variable,{}) but I received an error saying "Invalid types, can only act on data of the same type (Number (Integer), Any Type)", union(local!variable, local!Variable) but that did nothing.

I'm pretty sure my error is in the last line of code I'm just not sure how to match it with an integer value or if there is something else that I am missing. Any help is appreciated! Thank you.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    The things you explain and the code snippet do not really match. Can you share more of the code?

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Apologies, maybe I was not clear but that is all the code.

    I made this expression rule that calls the a!queryprocessAnalytics().totalCount,

    then there is the list that runs the one singular local variable,

    then the record's view page has an IF() statement that will display the text depending on the number given from the expression rule.

    So in a perfect world, the expression rule provides the appropriate TotalCount based on the orderID, then the record will display the correct page name depending on what value the expression rule produces. At thye moment it is working for most of the records, but some of them seem to have a totalCount that is higher that what should be there.

    The expression rule looks to the correct record, contectProcessModels and has the query parameter to look for the orderID rule input all looking to produce the totalCount. I had another user story identical to this but the type was a text so it allowed me to just do length(union(local!variable, {})) but since orderId is a integer I am receiving an error. The code I provided is essentially what is in Appian, I hope this helps or can clear up any confusion!

  • 0
    Certified Lead Developer
    in reply to nickk1385
    I made this expression rule that calls the a!queryprocessAnalytics().totalCount,

    OK, so this returns a single integer, correct?

    then there is the list that runs the one singular local variable,

     ...... what !?!?!? .....

    Then, what is that "length(union(local!variable, {}))" about?

    In my perfect world, you need to split your issue into smaller pieces, solve each, and then reassemble it. If something does not behave as expected, create a separate test case and only continue if you either found and fixed the bug, or have an explanation for that behaviour.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Yes, the expression rule is defined in a local variable, then I use the local variable (the query parameter), and it will return a single integer. I said the "length(union(loval!var, {}))" because for some of the queries, the expression rule will return the value 2, when there is only 1 order. And on the other user story that is identical to this, I used that line of code, length(union(loval!var, {})), to have the expression rule return the correct number but in this case it is returning the error message in the first post. I'm not sure what I have to do for this story, but I know that just having local!var is not correct and I need to wrap that line in something else. 

    All in all, what I am asking is what do I need to wrap that local variable in (after it is defined) to give the appropriate results given that the variable is a integer type. 

  • 0
    Certified Lead Developer
    in reply to nickk1385

    Sorry to say that, but you need find the reason for that behaviour, not try to fix it later! Just copy&pasting some code from elsewhere, that solves a different problem, will only get you into serious trouble!

    BTW, the following code (I fixed the issues in it):

    a!localVariables(
      local!var: 2,
      length(union(local!var, tointeger({})))
    )

    returns "1" instead of "2". But for a whole different reason, as it counts the items in the list. 

    I strongly suggest to rethink your approach to problem solving.

    www.freecodecamp.org/.../how-to-think-like-a-programmer-lessons-in-problem-solving-d1d8bf1de7d2

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    I think you are misunderstanding my question. I am not trying to "fix it later" and copying&pasting some random code from elsewhere, I was giving an example of a successful line of code that worked for an almost identical user story where the input type was text, I understand it won't work here since orderId is an integer. I also understand where the issue is, and it is in that one line of code, meaning that length(union(locl!var, {}) is incorrect and needs to have some adjustment so I don't receive the error message in my original post. I had no real intention of using the length(union()) function, but I know just using the local variable will return an incorrect value on multiple occasions, meaning the local variable needs to be wrapped in something to account for some issues that I was unaware of needed to be considered. I don't believe there is anything wrong with "my approach to problem solving" since I know what the issue is, where the issue is, I just didn't know what line of code to use instead of local!var. Thanks for the link but it is not relevant/helpful in this case. I was able to connect with another developer who was able to answer my question, so I no longer need help. Have a good day

  • 0
    Certified Lead Developer
    in reply to nickk1385

    OK. Now you made me curious. What was the actual issue and how did you solve it?

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    It was in with the .totalCount part of the a!queryProcessAnalytics().totalCount , once I switched it to .data, it was no longer giving me an error of two unmatchable types when I used the length(union(local!var, {})) function. So I guess it was because the totalCount part was only allowed for integers and obviously the {} isn't an integer. My coworker explained it in a lot more detail but it really seems to stems down to .totalCount not being appropriate and switching it with .data was the solution given the function I used.

    Now I'm sure there were other solutions as well but this worked in this case.

  • 0
    Certified Lead Developer
    in reply to nickk1385

    OK. I understand. Thanks for the clarification.

  • 0
    Certified Associate Developer
    in reply to Stefan Helzle

    Of course, and thank you for your help! I appreciate it!

Reply Children
No Data