with( /* Get the first CDT containing one or more of the following: Logical Expression, Query Filter, Search Query. It is called a logicalExpression|filter|search -- abbreviated as LFS */ local!parentLFS: index( ri!rspQueryObj, "logicalExpression|filter|search", null ), /* Check to see if the above CDT has a nested LFS in it. This can happen if the user has clicked multiple filters or searched on filtered results. */ local!childLFS: index( local!parentLFS, "logicalExpression|filter|search", null ), /* Get the LFS containing the filter(s) and/or search. Basically, if the child exists, it will contain all the information. If it doesn't then we want to parent. */ local!mainLFS: if( isnull( local!childLFS ), local!parentLFS, local!childLFS ), /* Get runtime types of LFS (type!QueryFilter or type!Search) */ local!types: apply( fn!runtimetypeof, { local!mainLFS } ), /* Get the search CDT, if there is one. It has its own type that we can look for. */ local!searchCdt: index({local!mainLFS}, where(local!types='type!{http://www.appian.com/ae/types/2009}Search'), null), /* Gets filter CDTs if there are any. We can find them by their type. */ local!filterCdts: index({local!mainLFS}, where(local!types='type!{http://www.appian.com/ae/types/2009}QueryFilter'), {}), local!recSearchText: if( isnull( local!searchCdt ), "", tostring( index( cast( 'type!{http://www.appian.com/ae/types/2009}Search', local!searchCdt ), "searchQuery", "" ) ) ), local!recFilters: if( rule!APN_isEmpty( local!filterCdts ), {}, cast('type!{http://www.appian.com/ae/types/2009}QueryFilter?list', local!filterCdts) ), /* Get filters' fields and values to avoid function repitition */ local!filterFields: if(rule!APN_isEmpty(local!recFilters), {}, index(local!recFilters, "field", {})), local!filterValues: if(rule!APN_isEmpty(local!recFilters), {}, index(local!recFilters, "value", {})), /* Get filtered 'Request Status' */ local!requestStatusFilterValues: if( rule!APN_isEmpty(local!filterFields), "", displayvalue( "requestStatus_txt", local!filterFields, local!filterValues, null ) ), /* Get filtered 'Request Type' */ local!requestTypeFilterValues: if( rule!APN_isEmpty(local!filterFields), "", displayvalue( "requestType_txt", local!filterFields, local!filterValues, null ) ), a!queryEntity( entity: cons!WMG_GBL_REQ_TRACK_VIEW_ENTITY, query: a!query( logicalExpression: a!queryLogicalExpression( operator: "AND", filters: { /* Default Filter */ a!queryFilter( field: "businessUnit_txt", operator: "=", value: ri!businessUnit_txt ), if( rule!APN_isEmpty( local!requestTypeFilterValues ), {}, a!queryFilter( field: "requestType_txt", operator: "=", value: local!requestTypeFilterValues ) ), if( rule!APN_isEmpty( local!requestStatusFilterValues ), {}, a!queryFilter( field: "requestStatus_txt", operator: "=", value: local!requestStatusFilterValues ) ) }, logicalExpressions: a!queryLogicalExpression( operator: "OR", filters: { if( rule!APN_isBlank( local!recSearchText ), {}, { a!queryFilter( field: "requestId_int", operator: "=", value: local!recSearchText ), a!queryFilter( field: "accountNumber_txt", operator: "=", value: local!recSearchText ), a!queryFilter( field: "clientName_txt", operator: "=", value: local!recSearchText ), a!queryFilter( field: "taxIdValue_txt", operator: "=", value: local!recSearchText ) } ) } ) ), pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 10, sort: a!sortInfo( field: "createdDate_dt", ascending: false ) ) ) ) )