Drop down value with Nested CDT

Hello, 

I have a record table and a nested funding type table. The record has typical information but I normalized the database to have some sections in their own tables and nested them according to documentation. For the drop down, the choices are populated by a expression rule that grabs the names of the funding types. I then have a index on the front end {index(rule!RP_GETfundDropDown().data, "fundTypeName", null)} grabbing the names. I then added the primary key of the fundtype table as well and listed those as the choice values. The goal was that I would just need to insert the id of the funding type into the record record type and it would be a reference fk. Instead, it is requiring the whole array of objects. See image. I am not entirely sure what I am doing wrong or why its expecting me to pass the whole row when it's referenced as a fk. 

Get_FundType

a!queryEntity(
entity: cons!FundTypeNames,
query: a!query(
selection: a!querySelection(
columns: {
a!queryColumn(
field: "fundTypeId"
),
a!queryColumn(
field: "fundTypeName"
)
}
),
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 50
)
),
fetchTotalCount: false
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I understand your issue up to choiceValues. What do you mean with

    "The goal was that I would just need to insert the id of the funding type into the record record type and it would be a reference fk. Instead, it is requiring the whole array of objects. See image. I am not entirely sure what I am doing wrong or why its expecting me to pass the whole row when it's referenced as a fk. "

    The dropDown returns one of the values you give as choiceValues. It does not magically know about any record.

    What is your expectation?

  • Hello,

    In an application, I would insert the id of the fund type into the record table and it would inherit the data from second table because of the foreign key. I have my choice labels as: {index(rule!RP_GETfundDropDown().data, "fundTypeName", null)} and my choice values as {index(rule!RP_GETfundDropDown().data, "fundTypeId", null)}. I am getting back an integer as expected but when I try to insert that choice into the data, it expects all of the data. I don't expect it to inherently know but I would expect it to take the integer and be fine. Instead it gives me Could not cast from Number (Integer) to fundType. Details: CastInvalid because it's trying to cast the integer as an fundType CDT. Why can't I just insert the FK id?

  • 0
    Certified Lead Developer
    in reply to rb0002
    Why can't I just insert the FK id?

    I'm not sure what you mean by this.  Are you talking about on the SAIL form?  If so, there's no such thing inherently as "insert the FK".  If your Save target is an integer, you would save the value of the selected row ID into it.  I notice you haven't posted your dropdown's SAIL code, so we can only but guess as to what you're actually trying to do in your SaveInto.

  • 0
    Certified Lead Developer
    in reply to rb0002

    Appian does not do this kind of things magically in the background. If you want the full "object", then you need to query it from DB.

  • I am grabbing the fund table to create the choice labels and values, then saving the integer (fundTypeId) into the requirement table. See the below additional information

    The expression for the drop down  is:

    a!dropdownField(
                  label: "Fund Type",
                  labelPosition: "ABOVE",
                  placeholder: "--- Select a Value ---",
                  choiceLabels: {index(rule!RP_GETfundDropDown().data, "fundTypeName", null)},
                  choiceValues: {index(rule!RP_GETfundDropDown().data, "fundTypeId", null)},
                  value: ri!requirements.fundtypeId,
                  saveInto: ri!requirements.fundtypeId,
                  searchDisplay: "AUTO",
                  validations: {}

    My record format:

    The fundType data pulled in the rule to populate the dropdown

  • 0
    Certified Lead Developer
    in reply to rb0002

    First and advice. If you put the DB query twice into the component, then Appian will query that twice on each user interaction. Store the data in a local variable first, then use it in the component.

    Second. Using a field name like "fundtypeId" to store a nested CDT is confusing.

    Now for the solution: Change you saveInto to something like

    a!save(
      target: ri!requirements.fundtypeId,
      value: rule!QUERY_FETCHING_SINGLE_ITEM(id: save!value)
    )

    should do it.

    You might want to change your value field to: ri!requirements.fundtypeId.fundtypeid.

  • +1
    Certified Lead Developer
    in reply to rb0002

    As Stefan mentioned - your CDT has the field "fundTypeId" but its data type is actually the CDT.  I have no idea why you'd do this.  I tend to avoid nested CDTs like this altogether, because it's almost always exponentially easier to just work with flat data.  I recommend you edit your CDT and change this field to just be Integer type.

  • I agree with Mike, Nested CDTs are a pain. Also, you can always create views or query both tables if you ever need to fetch info. 

    I would also like to add that you can query the data from you table and save it in a local variable and then use that local variable to index the id and value in the dropdown field. This would minimize the number of DB calls you make.

  • Thank you. I removed the Nested CDT and worked with a flat structure and was able to create a data model in the record to mimic a database structure. I assumed that the nested CDT was mimicking that join that I expected to see in a database structure. Thank you all for your help. 

Reply Children
No Data