Expression-Backed Record - multiple user filters

Hello,

 I created a expression-backed record with the help of the Appian tutorial : https://docs.appian.com/suite/help/19.3/Service-Backed_Record_Tutorial.html

I replaced the facet part by a!recordFilterListOption. It worked well. A filtering list on one of my record fields appeared and my data were filtered by my selection.

Now, I would like to have 2 filtering lists in order to have the ability to filtre on 2 fields of my record.

Is it possible ?

I tried with a code in the User Filters pane that looks like the code below but I got a message error : The User Filters expression failed to evaluate. Details: [Expression evaluation error at function 'localvariables': A variable is incorrectly defined. Parameter: 2. Expected syntax: localvariables(local!a, ..., expr) or localvariables(local!a:10, ..., expr)]. (APNX-1-4205-019)

Moreover, is there a wa to bypass the limit of 1 000 char  of this pane ?

Can someone help me ?

Thank you 

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

a!localVariables(
....
,
a!recordFilterList(
name: "Field 1",
....
),
a!recordFilterList(
name: "Field 2",
....
)

  Discussion posts and replies are publicly visible

Parents
  • +1
    Certified Lead Developer

    Moreover, is there a wa to bypass the limit of 1 000 char  of this pane ?

    Move your code into an expression rule, and just call the expression rule in the User Filters panel.

    I tried with a code in the User Filters pane that looks like the code below but I got a message error

    When you do a local variable definition, Appian expects that there be exactly one expression after any local variables are defined.  In your example above you have two - each of the a!recordFilterList() calls.

    The fix for this is simple - wrap everything in an array (which fulfills the "exactly one expression" requirement):

    a!localVariables(
      local!var1,
      local!var2,
      
      {
        a!recordFilterList(
          name: "Field 1",
          ....
        ),
        a!recordFilterList(
          name: "Field 2",
          ....
        )
      }
    )

Reply
  • +1
    Certified Lead Developer

    Moreover, is there a wa to bypass the limit of 1 000 char  of this pane ?

    Move your code into an expression rule, and just call the expression rule in the User Filters panel.

    I tried with a code in the User Filters pane that looks like the code below but I got a message error

    When you do a local variable definition, Appian expects that there be exactly one expression after any local variables are defined.  In your example above you have two - each of the a!recordFilterList() calls.

    The fix for this is simple - wrap everything in an array (which fulfills the "exactly one expression" requirement):

    a!localVariables(
      local!var1,
      local!var2,
      
      {
        a!recordFilterList(
          name: "Field 1",
          ....
        ),
        a!recordFilterList(
          name: "Field 2",
          ....
        )
      }
    )

Children
  • Thank you Mike for your answer !

    I have one more question, maybe you have the answer : 

    In my usecase, I have a record that contains fields eventId and incidentId that refere to external table .

    Record :

    eventId -> id (event table)

    incidentId -> id (incident table)

    I want to set filter on these both fields.

    I am able to display the filter lists using an integration object for each table (API calls).

    My expression looks like : 

    {
    a!recordFilterList(
        name: "eventId ",
        ....
        expression: a!recordFilterListOption(
            id: fv!index,
            name: fv!item.label,
            filter: a!queryFilter(
            field: "id" ,
            operator: "=",
            value: fv!item.id
        )
    ),
    a!recordFilterList(
        name: "incidentId ",
        ....
        expression: a!recordFilterListOption(
            id: fv!index,
            name: fv!item.label,
            filter: a!queryFilter(
            field: "id" ,
            operator: "=",
            value: fv!item.id
        )
    )
    }

    My problem is : the both fields that I want to filter have the same name : id

    How can I contextualise my id's in the List View Source Expression :

    a!localVariables(
      local!incidentIdIndex: wherecontains("id" /*this is id of the filter event*/, index(rsp!filters, "field", "")),
      local!incidentId: if(
        length(local!incidentIdIndex) > 0,
        index(rsp!filters, "value",""),
        ""
      )
     local!eventIdIndex: wherecontains("id" /*this is id of the filter event*/, index(rsp!filters, "field", "")),
      local!eventId: if(
        length(local!eventIdIndex) > 0,
        index(rsp!filters, "value",""),
        ""
      )
      ,

    Regards,

    Julien

  • 0
    Certified Lead Developer
    in reply to Julien Fontaine

    That seems to get into complexities of where your data is being accessed via the API calls, which I honestly have less familiarity with - and i think it depends a lot on specific context that I don't have.  Someone else here may have handled this sort of thing in the past, and might have more useful feedback for you.  Just as a first guess - do you happen to have any ability to alias certain incoming fields in the API call(s)?

  • I don't know if I can alias but it can be a good start.

    Do you know a way to display the content of the rsp!filters variable used in the List View Source Expression ?

    I would like to see it for "debugging"

  • 0
    Certified Lead Developer
    in reply to Julien Fontaine

    The documentation defines rsp!filters as "An array containing the record type's default filters as well as the user filter selections."

    Basically this ends up meaning that I can't tell you how to see what the actual value is at runtime, but you can deduce what the value is by whatever value (if any) you have defined for your Default Filters and User Filters - which, as far as I know, boils down to a list of a!queryFilter.

    In my case, I'm able to test out my list view source expression Expression Rule by typing an array of valid a!queryFilter() entries in the "Expression" box for ri!filters (or just leave it blank to test a default query).

    That being said, I still believe you'll need to figure out a way to differentiate the two different types of "id" before you get to this point.  I'm still a little unclear on the source of the incoming data types - are they mapped to Appian data types or something else?  In what way do the two different tables end up being queried by the same record source expression?

  • I will try to explain my usecase : 

    I have a main data type named incident that composed by several fields including a field incidentType that referes to a data type named incidentType and another filed eventType that referes to a data type named eventType.

    ______________________
    incident :
        id,
        incidentType,
        eventType,
        ...
    ______________________
    
    ______________________
    incidentType :
        id,
        ...
    ______________________
    
    ______________________
    eventType :
        id,
        ...
    ______________________

    I display the record list of incident and I use filter list (the a!recordFilterList) on incidentType and eventType to filter my incident list.

    The alias way seems to be a good way but I don't know how to do that.

    I went deeper to the  rsp!filters and I was able to see what was hidding in the rsp!filters variable when I selected vaule in my both filters : 

    %5Bfield%3Did%2C+operator%3D%3D%2C+valueExpression%3D%2C+value%3D1%2C+validated%3D%5D%3B+%5Bfield%3Did%2C+operator%3D%3D%2C+valueExpression%3D%2C+value%3D19%2C+validated%3D%5D

    I guess :

    • %3D means =
    • %2C is a separator

    It appeared that I could set a parameter "valueExpression" in the a!queryFilter() that I could retrieved after in the rsp!filters variable. That could be the way to contextualize my id's without changing my data types.

    I will try that.

  • I finally succeeded ! By better reading the documentation, it appeared that the value for the field "field" in the queryFilter function referes to one of the Record fields and not to the external table.

      a!recordFilterList(
          name: "incidentType",
          allowMultipleSelections: false,
          options: a!forEach(
            items: local!status,
            expression: a!recordFilterListOption(
              id: fv!index,
              name: fv!item.label,
              filter: a!queryFilter(
                field: "incidentType.id" , /* this referes to the field of Record Type display in the list */
                operator: "=",
                value: if(isnull(fv!item.id), "",fv!item.id)
              )
            )
          )
        )

    After that, I can get it from the rsp!filters variable :

    index(index(rsp!filters,wherecontains("incidentType.id", index(rsp!filters,"field", {""}))),"value","")