I want to return unique values from a data store using just a rule and query. Th

I want to return unique values from a data store using just a rule and query. This is what I have so far but I can't seem to figure out how to leverage the target field array. for the union function to operate on.
=union(todatasubset(rule!GetAllLrules().PUB),todatasubset(rule!GetAllrules().PUB))
So the .PUB part delivers the data sub set how do I then navigate to the field within it?
Ideas and outright solutions most welcome.
Thanks, James

OriginalPostID-147436

OriginalPostID-147436

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    Ah, I see. Sorry, your last sentence confused me a bit since it seemed like you were saying something else.
    AFAIK, there probably isn't a need to wrap the rule outputs in todatasubset() here - it's used to wrap a data output in some container data for use in other applications such as paging grids, as well as some corner case applications like forced sorting. If you're just after the raw data, basically rule!GetAllLrules().PUB, then I'd start off without that.

    I'm going to write this on the assumption that you're putting this in an expression rule to be called universally.
    First, I strongly recommend reducing your calls of the query rule since you're currently calling it twice. This is pretty easy to do by utilizing with() functionality.

    There are 2 equivalent approaches I will cover here - In option A, we load the whole CDT into a PV, then deal with the details. In option B, we load just the raw data of the .PUB field.

    A:
    with(
    local!cdtData: rule!GetAllLrules(),

    union(
    property( local!cdtData, "PUB", {} ),
    property( local!cdtData, "PUB", {} )
    ) /* we could just type "local!cdtData.PUB" in each of the above, but using Property() protects us against cases where the query returns empty */
    )

    B:
    with(
    local!PUBData: rule!GetAllLrules().PUB, /* we would want to use property() here, too, if there's any chance the query would return empty. otherwise it's about the same. */

    union( local!PUBData, local!PUBData )
    )

    I hope I'm not totally off-base with these - let me know if you need any further clarification etc.
Reply
  • 0
    Certified Lead Developer
    Ah, I see. Sorry, your last sentence confused me a bit since it seemed like you were saying something else.
    AFAIK, there probably isn't a need to wrap the rule outputs in todatasubset() here - it's used to wrap a data output in some container data for use in other applications such as paging grids, as well as some corner case applications like forced sorting. If you're just after the raw data, basically rule!GetAllLrules().PUB, then I'd start off without that.

    I'm going to write this on the assumption that you're putting this in an expression rule to be called universally.
    First, I strongly recommend reducing your calls of the query rule since you're currently calling it twice. This is pretty easy to do by utilizing with() functionality.

    There are 2 equivalent approaches I will cover here - In option A, we load the whole CDT into a PV, then deal with the details. In option B, we load just the raw data of the .PUB field.

    A:
    with(
    local!cdtData: rule!GetAllLrules(),

    union(
    property( local!cdtData, "PUB", {} ),
    property( local!cdtData, "PUB", {} )
    ) /* we could just type "local!cdtData.PUB" in each of the above, but using Property() protects us against cases where the query returns empty */
    )

    B:
    with(
    local!PUBData: rule!GetAllLrules().PUB, /* we would want to use property() here, too, if there's any chance the query would return empty. otherwise it's about the same. */

    union( local!PUBData, local!PUBData )
    )

    I hope I'm not totally off-base with these - let me know if you need any further clarification etc.
Children
No Data