Skip to main content
September 29, 2022
Question

To filter date in expression rule

  • September 29, 2022
  • 11 replies
  • 0 views

Hi All,

My scenario is to filter the below view column in appian expression rule using the two rule inputs of "date" dataype(startDate,EndDate),

We can see in screenshot, the  column is of text and its in concatenated way, is it possible to filter this from appian?

Could you please help me on this.

Thanks in Advance.

    11 replies

    amans0009
    September 29, 2022

    you can extract the dates like this 

    a!localVariables(
      local!data:"04.01.2022 To 06.30.2022",
      local!Date:split(local!data," "),
      local!ansDate: a!map(start:todate(index(local!Date,1,{})),end:todate(index(local!Date,length(local!Date)))),
     local!ansDate
    )

    harshitb6843
    September 29, 2022

    I don't think it can help. The requirement is to filter and with the way the data is stored, it will not be straight forward. 
    I have a way to achieve it tho. You will have to create an exactly matching string with your start date and your end date. and then pass that value with the "includes" parameter in the queryFilter()

    September 29, 2022

    Thanks for responding back.

    I am not getting your point,could you please explain?

    Data : "04.01.2022 to 06.30.2022; 01.01.2020 to 03.31.2020; 10.01.2020 to 06.30.2022; 07.01.2021 to 06.30.2022"

    RuleInput1 : Jan 1 2020

    RuleInput2 : Mar 31 2020

    Expected Output: Above data i should get as a result

    September 29, 2022

    Yes it is possible you can apply the selection the particular column and use >= and <= to fetch the data between two dates and concat them using to string.

    Your query will be like this

    
      a!queryEntity_22r2(
        entity: cons!AA_VEHICLES_DSE_POINTER,
    
        query: a!query(
          selection: a!querySelection(
            columns: a!queryColumn(
              field: "vehicleDateAdded"
            )
          ),
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
    
              a!queryFilter(
                field: "vehicleDateAdded",/*field Name*/
                operator: ">=",
                value: ri!startDate
              ),
              a!queryFilter(
                field: "vehicleDateAdded",/*field Name*/
                operator: "<=",
                value: ri!endDate
              )
            },
            ignoreFiltersWithEmptyValues: true
          ),
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: 10
          )
        ),
        fetchTotalCount: false
      ).data
    

    September 29, 2022

    Thank you. But I am facing this below error,

    harshitb6843
    September 29, 2022

    a!queryFilter(
        field: "parIncludedPeriods_txt",/*field Name*/
        operator: "includes",
        value: concat(text(local!date1,"mm.dd.yyyy")," to ",text(local!date2,"mm.dd.yyyy"))
      )

    Change the variables date1 and date2 with your original onces.