Skip to main content
August 2, 2021
Solved

Drop down value with Nested CDT

  • August 2, 2021
  • 9 replies
  • 0 views

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
)

Best answer by mikes0011

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.

9 replies

stefanhelzle0001
Brainy
August 3, 2021

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?

rb0002Author
August 3, 2021

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?

mikes0011
Brainy
August 3, 2021
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.

The Expression Guru