nested CDTs and Writing Data to Database

Hi, I have multiple CDTs that have various relationships set up. What I am not clear on is how the ids that would enable the records to relate appropriately are passed from the parent CDT to the child CDT? For example, if an app allows you to create a customer and that customer has many phone numbers, I would have a parent CDT with a one to many relationship with a phone number CDT. When a user enters information into the form, how should the customer key flow into the phone number CDT to allow the relationship to work? Is it expected that this occurs automatically, or would you just program for this where a script task runs in the process model to add the applicable customer id into the applicable phone number rows in the child CDT? (i.e. script task using: repeat(count(pv!childCDT),pv!parentCDT.id) 

 

THANKS!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer

    Appian manages the child key automatically.  Your nested phone record could be populated in an editable grid as shown below inside your customer grid.  You will notice that nowhere the customer id (key) is being referenced.

    a!gridLayout(
    label: "Phone Records",
    labelPosition: "ABOVE",
    emptyGridMessage: "No records found.",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Phone Number")
    },
    columnConfigs: {
    a!gridLayoutColumnConfig(width: "DISTRIBUTE", weight: 5)
    },
    rows: a!forEach(
    items: fv!item.phoneFK, /* fv!item is your customer variable, depending on how you set it up, it could very well be customer.phoneFK */
    expression: a!gridRowLayout(contents: { a!textField() })
    ),
    addRowLink: a!dynamicLink(
    label: "Add Phone",
    saveInto: a!save(
    target: fv!item.phoneFK,
    value: append(
    fv!item.phoneFK,
    'type!{urn:com:appian:types:APP}PHONECDT'()
    )
    )
    )
    ),

Reply Children
No Data