Populate PickerfieldCustom from a CDT

I'm fairly new to Appian so any help is greatly appreciated.

I found this example on how to populate a PickerfieldCustom  with static data but I'm wanting to use a table from a database via a CDT.

The table has 2 columns (id, descr). I already created a CDT for it and works fine.

The PickerfieldCustom  needs to display the descr field and the value needs to be the id.

Are there any good examples for this? If not can someone give me some guidance?

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    ,

    Below code may help you.

    a!pickerFieldCustom(
    label: "Select Data"
    placeholder: "Type Min 3 characters",
    labelPosition: "JUSTIFIED",
    required: true(),
    maxselections: 1,
    suggestFunction: ##Write Expression rule to get ID & Desc Data from Data base# Use index function to get data index. Also, in Query entity Filter use operator: "includes" ##
    selectedLabels: index(
    rule!getDetailsByID(
    Id_int: local!selectedId
    ),
    "Desc",
    null
    ), #Here get details from table by passing Id #
    value: local!selectedId,
    saveInto: {
    local!selectedId,
    )

    Thanks,
    Sandeep

  • The easiest way to set this up with data from a database is to create a query that returns all of the data from your CDT. Then, just replace the "labels" list with your description and the "abbreviations" list with your id. Keep in mind you might need to also change some of the data types for your supporting rule (for instance, the "identifiers" rule input should be an integer instead of text). If you do this correctly, your final expression could look something like this:

    a!localVariables(
      local!selection,
      local!data: rule!GetAllReferenceData(),
      a!pickerFieldCustom(
        label: "Label",
        instructions: "Value saved: " & local!selection,
        maxSelections: 1,
        suggestFunction: rule!ucArrayPickerFilter(
          filter:_ , 
          labels: local!data.desc, 
          identifiers: local!data.id
        ),
        selectedLabels: a!forEach(
          items: local!selection,
          expression: index(local!data.desc, wherecontains(fv!item, local!data.id))
        ),
        value: local!selection,
        saveInto: local!selection
      )
    )

  • Hi Peter,

    First off, love you training videos. They are very helpful. Keep up the good work!

    I think I'm close but seems that I'm not quite there yet. Seems to be a problem in the selectedLabels, specifically the forEach expression. I'll attach some screenshots. Maybe you guys can spot something I'm overlooking.

  • 0
    A Score Level 1
    in reply to htmoore

    Hey , please add .data at the end of your query entity (line 25) ADA_lookupadvisors so that it gives you data in dictionary type format ( excluding startIndex, totalcount , batchsize etc) . Alternatively , In the interface, you can define the local  variable like this : local!data : rule! ADA_lookupadvisors().data.  You can try any of the above two methods. That should work.

  • That did the trick! Thank you! With a little tweak it worked great. Had to add touniformstring() in the wherecontains() but other than that, it is working as expected. 

    Thanks Peter, st07, and sandeepd. :-)

    Here's the final code:

    a!pickerFieldCustom(
        label: "Select Faculty Advisor",
        labelPosition: "ABOVE",
        instructions: "Search for Faculty Advisor by name or employee Id",
        placeholder: "Enter names here",
        maxSelections: 1,
        suggestFunction: rule!ADA_LookupAdvisorsFilter(
          filter: _,
          labels: local!data.name,
          identifiers: local!data.emplid
        ),
        selectedLabels: a!forEach(
          items: local!selection,
            expression:
          index(local!data.name, 
            wherecontains(
              fv!item,
              touniformstring(local!data.emplid)
            )
          )
        ),
        saveInto: local!selection,
        value: local!selection
    )

  • 0
    A Score Level 3
    in reply to htmoore

    Just to add one more thing. In case you can choose from a large amount of items, it is not a good idea to load all into memory and pass them into the suggest function. In this case you should implement a dynamic query from DB inside the suggest function.