How to save data spanned over multiple CDTs columns?

My scenario is to create an editable grid which takes user data and simply save into the database but the catch is the column data in the grid is from multiple different CDTs or tables. 

For example : Two columns "Quantity" and "Price" are from one CDT table called "Request"

Another one column "Comment" is from table "Comment" and there is "RequestType" from reference table "RequestTypeRef" which can have any of the two values "Supply" or "Service" and lastly "Item" which is dependent on "Request Type", if it is "Supply" then "Item" should save in "SupplyTypeName" of "SupplyTypeRef", else in "ServiceTypeRef".

Below is the code I've written and for now taking rule inputs as requestrequestTypeRefserviceTypeRefsupplyTypeRef and comment, all are array of these datatypes because user can make multiple requests (not more than 5) at a time.

For better understanding, attaching the screenshot of what I've developed so far.

a!localVariables(
  a!formLayout(
    label: "Create New Request",
    instructions: "Create a new Request Type, maximum 5 requests can be created at a time",
    contents: {
      a!gridLayout(
        headerCells: {
          a!gridLayoutHeaderCell(
            label: "Request Type"
          ),
          a!gridLayoutHeaderCell(
            label: "Item",
            helpTooltip: "Enter the Item Name to request"
          ),
          a!gridLayoutHeaderCell(
            label: "Quantity"
          ),
          a!gridLayoutHeaderCell(
            label: "Price ($)"
          ),
          a!gridLayoutHeaderCell(
            label: "Comment"
          )/*,*/
          /*a!gridLayoutHeaderCell(*/
          /*label: ""*/
          /*)*/
          
        },
        columnConfigs: {
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 3
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 3
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 3
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 3
          ),
          a!gridLayoutColumnConfig(
            width: "DISTRIBUTE",
            weight: 3
          ),
          a!gridLayoutColumnConfig(
            width: "ICON"
          )
        },
        rows: a!gridRowLayout(
          contents: {
            a!dropdownField(
              label: "request type",
              placeholderLabel: "-- Please Select-- ",
              choiceLabels: cons!OSR_TEXT_ARRAY_REQUEST_TYPE,
              choiceValues: cons!OSR_TEXT_ARRAY_REQUEST_TYPE,
              value: index(
                ri!requestTypeRef,
                "RequestTypeName",
                {}
              ),
              saveInto: ri!requestTypeRef.RequestTypeName,
              required: true
            ),
            a!textField(
              label: "item",
              value: if(
                ri!requestTypeRef.RequestTypeName = "Service",
                index(
                  ri!serviceTypeRef,
                  "ServiceTypeName",
                  {}
                ),
                index(
                  ri!supplyTypeRef,
                  "SupplyTypeName",
                  {}
                )
              ),
              saveInto: if(
                ri!requestTypeRef.RequestTypeName = "Service",
                ri!serviceTypeRef.ServiceTypeName,
                ri!supplyTypeRef.SupplyTypeName
              ),
              required: true
            ),
            a!integerField(
              label: "quantity",
              value: index(
                ri!request,
                "Quantity",
                {}
              ),
              saveInto: ri!request.Quantity,
              required: true
            ),
            a!textField(
              label: "price",
              value: todecimal(
                index(
                  ri!request,
                  "Price",
                  {}
                )
              ),
              saveInto: ri!request.Price,
              required: true
            ),
            a!paragraphField(
              label: "comment",
              value: index(
                ri!comment,
                "Comment",
                {}
              ),
              saveInto: ri!comment.Comment
            )
          }
        ),
        rowHeader: 1
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: cons!OSR_TEXT_BUTTON_SUBMIT,
          submit: true,
          style: "PRIMARY"
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: cons!OSR_TEXT_BUTTON_CANCEL,
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

  Discussion posts and replies are publicly visible

Parents
  • a!localVariables(
      a!formLayout(
        label: "",
        contents: {
          a!gridLayout(
            totalCount: count(
              ri!name
            ),
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Name"
              ),
              a!gridLayoutHeaderCell(
                label: "Age"
              ),
              a!gridLayoutHeaderCell(
                label: "Comment"
              ),
              a!gridLayoutHeaderCell(
                label: ""
              )
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "ICON"
              )
            },
            rows: a!forEach(
              items: ri!name,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "first name " & fv!index,
                    value: fv!item,
                    saveInto: fv!item,
                    required: true
                  ),
                  a!textField(
                    label: "Age",
                    value: ri!age[fv!index],
                    saveInto: ri!age[fv!index],
                    required: true
                  ),
                  a!paragraphField(
                    label: "Comment",
                    value: ri!comment[fv!index],
                    saveInto: ri!comment[fv!index],
                    required: true
                  ),
                  a!imageField(
                    label: "delete ",
                    images: a!documentImage(
                      document: a!iconIndicator(
                        "REMOVE"
                      ),
                      altText: "Remove Employee",
                      caption: "Remove ",
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            ri!name,
                            remove(
                              ri!name,
                              save!value
                            )
                          ),
                          a!save(
                            ri!age,
                            remove(
                              ri!age,
                              save!value
                            )
                          ),
                          a!save(
                            ri!comment,
                            remove(
                              ri!comment,
                              save!value
                            )
                          )
                        }
                      )
                    ),
                    size: "ICON"
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Employee",
              value: null,
              saveInto: {
                a!save(
                  ri!name,
                  append(
                    ri!name,
                    save!value
                  )
                ),
                a!save(
                  ri!age,
                  append(
                    ri!age,
                    save!value
                  )
                ),
                a!save(
                  ri!comment,
                  append(
                    ri!comment,
                    save!value
                  )
                )
              }
            ),
            rowHeader: 1
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            submit: true
          )
        )
      )
    )
    

    use this code as reference 

Reply
  • a!localVariables(
      a!formLayout(
        label: "",
        contents: {
          a!gridLayout(
            totalCount: count(
              ri!name
            ),
            headerCells: {
              a!gridLayoutHeaderCell(
                label: "Name"
              ),
              a!gridLayoutHeaderCell(
                label: "Age"
              ),
              a!gridLayoutHeaderCell(
                label: "Comment"
              ),
              a!gridLayoutHeaderCell(
                label: ""
              )
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "DISTRIBUTE",
                weight: 3
              ),
              a!gridLayoutColumnConfig(
                width: "ICON"
              )
            },
            rows: a!forEach(
              items: ri!name,
              expression: a!gridRowLayout(
                contents: {
                  a!textField(
                    label: "first name " & fv!index,
                    value: fv!item,
                    saveInto: fv!item,
                    required: true
                  ),
                  a!textField(
                    label: "Age",
                    value: ri!age[fv!index],
                    saveInto: ri!age[fv!index],
                    required: true
                  ),
                  a!paragraphField(
                    label: "Comment",
                    value: ri!comment[fv!index],
                    saveInto: ri!comment[fv!index],
                    required: true
                  ),
                  a!imageField(
                    label: "delete ",
                    images: a!documentImage(
                      document: a!iconIndicator(
                        "REMOVE"
                      ),
                      altText: "Remove Employee",
                      caption: "Remove ",
                      link: a!dynamicLink(
                        value: fv!index,
                        saveInto: {
                          a!save(
                            ri!name,
                            remove(
                              ri!name,
                              save!value
                            )
                          ),
                          a!save(
                            ri!age,
                            remove(
                              ri!age,
                              save!value
                            )
                          ),
                          a!save(
                            ri!comment,
                            remove(
                              ri!comment,
                              save!value
                            )
                          )
                        }
                      )
                    ),
                    size: "ICON"
                  )
                },
                id: fv!index
              )
            ),
            addRowlink: a!dynamicLink(
              label: "Add Employee",
              value: null,
              saveInto: {
                a!save(
                  ri!name,
                  append(
                    ri!name,
                    save!value
                  )
                ),
                a!save(
                  ri!age,
                  append(
                    ri!age,
                    save!value
                  )
                ),
                a!save(
                  ri!comment,
                  append(
                    ri!comment,
                    save!value
                  )
                )
              }
            ),
            rowHeader: 1
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: a!buttonWidget(
            label: "Submit",
            submit: true
          )
        )
      )
    )
    

    use this code as reference 

Children