Skip to main content
August 19, 2024
Solved

pickerFieldCustom to not select a value.

  • August 19, 2024
  • 4 replies
  • 0 views

I have a custom picker field which is used to select the countries. From the list of all countries the user should not be able to select and save Great Britain and Northern Ireland. Can someone please suggest how I can achieve this.

Best answer by konduruc733182

In your query could you simply add a queryFilter with "not in" operator and exclude the two values?

4 replies

konduruc733182
August 19, 2024

Hello [mention:eafad29ef2f94635b373ae8b9e875dbc:e9ed411860ed4f2ba0265705b8793d05] 

Please share the code snippet. The simple answer is when you are creating the ER for Array Picker used in the suggestFunction of pickerFieldCustom, you need to remove the Great Britain and Northern Ireland values from the list that you are using for labels and identifiers.

August 19, 2024

 [mention:2df2892a4df7486f9775b4d2f0e405fd:e9ed411860ed4f2ba0265705b8793d05]  

Suggest function code:

/* Rule returns a data subset with data as Country name   identifier as ISO  code and with 20 entries at a time*/
a!localVariables(
  local!saveCountryOrIsoCode: rule!APN_replaceNull(
    nullableValue: ri!saveCountryNameOrIsoCode,
    replacementValue: false
  ),
  local!isClusterIncluded: toboolean(
    rule!APN_replaceNull(
      nullableValue: ri!isClusterIncluded,
      replacementValue: false
    )
  ),
  local!pagingInfo: rule!APN_replaceNull(
    nullableValue: ri!pagingInfo,
    replacementValue: a!pagingInfo(
      startIndex: 1,
      batchSize: 20,
      sort: a!sortInfo(field: "country_txt", ascending: true)
    )
  ),
  local!paginfoCluster: rule!APN_replaceNull(
    nullableValue: ri!clusterPagingInfo,
    replacementValue: a!pagingInfo(
      startIndex: 1,
      batchSize: 20,
      sort: a!sortInfo(field: "clusterName_txt", ascending: true)
    )
  ),
  local!data: if(
    rule!APN_isEmpty(ri!filter),
    null,
    a!queryEntity(
      entity: cons!RGRACSLBL_ENTITY_COUNTRY_REGION,
      query: a!query(
        selection: a!querySelection(
          columns: {
            a!queryColumn(field: "isoCode_txt", visible: true()),
            a!queryColumn(field: "country_txt", visible: true())
          }
        ),
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "region_txt",
              operator: ">",
              value: " "
            ),
            a!queryFilter(
              field: "country_txt",
              operator: "includes",
              value: ri!filter
            )
          }
        ),
        pagingInfo: local!pagingInfo
      )
    )
  ),
  local!data2: if(
    and(
      not(rule!APN_isEmpty(ri!filter)),
      local!isClusterIncluded
    ),
    a!queryEntity(
      entity: cons!RGRACSLBL_ENTITY_LABEL_LU_REF_CLUSTER,
      query: a!query(
        selection: a!querySelection(
          columns: {
            a!queryColumn(field: "clusterName_txt", visible: true())
          }
        ),
        logicalExpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "clusterName_txt",
              operator: "in",
              value: cons!RGRACSLBL_TEXT_CLUSTERS_REFERENCE_COUNTRY
            ),
            a!queryFilter(
              field: "clusterName_txt",
              operator: "includes",
              value: ri!filter
            )
          }
        ),
        pagingInfo: local!paginfoCluster
      )
    ),
    null
  ),
  if(
    local!isClusterIncluded,
    if(
      and(
        rule!APN_isEmpty(index(local!data, "data", null)),
        rule!APN_isEmpty(index(local!data2, "data", null))
      ),
      a!dataSubset(data: null, identifiers: null),
      a!dataSubset(
        data: reject(
          fn!isnull,
          append(
            index(
              index(local!data, "data", null),
              "country_txt",
              null
            ),
            index(
              index(local!data2, "data", null),
              "clusterName_txt",
              null
            )
          )
        ),
        identifiers: reject(
          fn!isnull,
          append(
            index(
              index(local!data, "data", null),
              if(local!saveCountryOrIsoCode,  "country_txt", "isoCode_txt"),
              null
            ),
            index(
              index(local!data2, "data", null),
              "clusterName_txt",
              null
            )
          )
        )
      )
    ),
    rule!APN_isEmpty(index(local!data, "data", null)),
    a!dataSubset(data: null, identifiers: null),
    a!dataSubset(
      data: index(
        index(local!data, "data", null),
        "country_txt",
        null
      ),
      identifiers: index(
        index(local!data, "data", null),
        if(local!saveCountryOrIsoCode,  "country_txt", "isoCode_txt"), 
        null
      )
    )
  )
)

konduruc733182
August 19, 2024

In your query could you simply add a queryFilter with "not in" operator and exclude the two values?

mikes0011
Brainy
August 19, 2024

In addition to Konduru's approach, you could always add a validation when the user DOES select one of these values.  Depending on the use case, this could be preferable sinec it might make more sense to users (as opposed to the option just not appearing, and them not understanding why).