Skip to main content
Inspiring
April 8, 2021
Solved

How to sort complex list

  • April 8, 2021
  • 6 replies
  • 0 views

Hello, 

How I can sort this by ClientName ?

    Best answer by mikes0011

    Can you enclose your "CXM_getClientName()" rule call on Line 39 within "toString()"?  Depending on the output of that rule it could be evaluating to a somewhat weird data type.

    6 replies

    mikes0011
    Brainy
    April 8, 2021

    Are you querying this from a database via a QueryEntity rule? If so, you can easily sort on a particular field via your a!pagingInfo() definition.

    If it's data you have inherent or manually-created in an interface or a rule, then it takes a bit more work.  Appian has no direct way to do this but a fairly easy indirect workaround, again involving pagingInfo.

    a!localVariables(
      local!dictionary: {
        {
          clientId: 1,
          clientName: "z client 1"
        },
        {
          clientId: 32,
          clientName: "a client name"
        },
        {
          clientId: 58,
          clientName: "middle client"
        }
      },
      
      todatasubset(
        local!dictionary,
        a!pagingInfo(
          startIndex: 1,
          batchSize: -1,
          sort: a!sortInfo(
            field: "clientName",
            ascending: true()
          )
        )
      ).data
    )

    The Expression Guru
    Inspiring
    April 8, 2021

    Hi Mike, I have tried this option but no luck, it shows error. 

    Expression evaluation error at function 'todatasubset' [line 42]: Cannot sort type {www.appian.com/.../2009}Dictionary by field clientName because it is a complex type {www.appian.com/.../2009}Variant. Sort by fields of primitive types only.

    mikes0011
    mikes0011Answer
    Brainy
    April 8, 2021

    Can you enclose your "CXM_getClientName()" rule call on Line 39 within "toString()"?  Depending on the output of that rule it could be evaluating to a somewhat weird data type.

    The Expression Guru