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", {})
      )
    )

Reply
  • +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", {})
      )
    )

Children