custom picker

Hi All,

        i have a requirement to create custom picker for populating country code based on the country name or country code entered.

for eg: if i enter USA then it should show 1 and if i enter  1 then it should show all the codes containing 1.

My doubt is will custom picker allow user to search from multiple data subsets(name and code).i have checked the documentation ,there it is mentioned using only single data subset. kindly provide your suggestions if possible with any examples.

Thanks in advance.

Pradeep.B

  Discussion posts and replies are publicly visible

Parents
  • Hi ,

    If my understanding of your question is correct, then the answer would be yes. We can configure the custom picker to search based on different field data(such as name and code) and we can configure this in the suggestion function rule. But however, only one data subset can be returned as an output from the suggestion function & can be used inside the picker.

  • Thank you for your reply.If possible can you please provide any example for suggestion function?

  • +1
    Certified Lead Developer
    in reply to pradeepb0001

    The following suggest function would do what you're asking for - matching either on exact country id or on country name.  As a bonus, a user would be able to type multiple parts of a country's name separated by a space and get results that have some match for all typed parts.  Thanks to the flexibility of the a!queryLogicalExpression() construct (with the ability to nest and loop to basically any extent you could possibly want), we have a lot of flexibility with what search results are achievable, this being just one of a multitude of different possibilities.

    a!localVariables(
    
      local!searchTextParts: a!forEach(
        split(ri!searchText, " "),
        if(rule!PROJECT_RULE_isBlank(fv!item), {}, fv!item)
      ),
    
      local!query: a!queryEntity(
        entity: cons!PROJECT_ENTITY_VIEW_COUNTRY_PICKER, /* DSE constant pointing to your countries table or view */
        query: a!query(
          logicalExpression: a!queryLogicalExpression(
            operator: "AND",
            filters: {
              a!queryFilter(
                field: "countryId", 
                operator: "not null"
              )
            },
            logicalExpressions: {
              a!queryLogicalExpression(
                operator: "AND",
                logicalExpressions: a!forEach(
                  local!searchTextParts,
                  
                  a!queryLogicalExpression(
                    operator: "OR",
                    filters: {
                      a!queryFilter(
                        field: "countryId",
                        operator: "=",
                        value: fv!item,
                        applyWhen: not(rule!PROJECT_RULE_isBlank(tointeger(fv!item)))
                      ),
                      a!queryFilter(
                        field: "countryName",
                        /* OPERATOR can be either "starts with" or "includes" depending on your preference and/or project requirements */
                        operator: "includes",
                        value: tostring(fv!item)
                      )
                    }
                  )
                )
              )
            }
          ),
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: 20,
            sort: a!sortInfo(
              field: "countryId",
              ascending: true()
            )
          )
        )
      ),
    
      a!dataSubset(
        data: a!forEach(
          local!query.data,
          rule!PROJECT_Format_countryPickerLabel(country: fv!item) /* this rule would accept the Country CDT and return a single line of text representing how the Country name (and other details if desired) will appear in suggestion results as well as in the selected items list in the parent rule */
        ),
        identifiers: property(local!query.data, "countryId", {})
      )
    )

  • +1
    Certified Lead Developer
    in reply to Mike Schmitt

    As a followup: you would also be able to make the search work for "any country ID that contains the character '1'", however you would need a special column in your view, in which you cast the country ID to VARCHAR (text) instead of integer, as appian queries are unable to do an "includes" style query on integers.  I just did this recently and it works like a charm. 

    For this scenario you should definitely use a view, and the text-cast column should be an *additional* column.  As long as you've done that, then you would replace the "countryId" component of the filter set with the following, which is actually slightly more simple:

    a!queryFilter(
      field: "countryIdText",
      operator: "includes",
      value: fv!item,
      /* applyWhen: not(rule!PROJECT_RULE_isBlank(tointeger(fv!item))) */
    ),

  • i made some modification to your code and it worked perfectly.Thank you very much.

  • 0
    Certified Lead Developer
    in reply to pradeepb0001

    cool, thanks for confirming/verifying.

  • Hello, good morning, I'm sorry. I occupy the same thing that you can't stay. What did you modify? your answer would help me a lot

Reply Children
No Data