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
  • +1
    Certified Lead Developer

    Your primary issue is that you're only defining one row in the rows: parameter of your grid.  This should instead be an array of a!gridRowLayout() objects (not just one like you currently have).  Krishna's example above has this configured correctly, for reference.  In your case I'd guess you should iterate over your ri!requestTypeRef array (using a!forEach) and define the rows that way.  Luckily this only requires a few specific edits to your current code.

    Secondly I'm a bit confused what you're trying to do while saving into serviceTypeRef or supplyTypeRef - if these each are associated with a specific "Request Type" row, where is the logical connection between them?  From your screenshot I can tell that "service type ref" has only ID and Name as distinguishing features, so what relation does each entry of this have to a specific supply type row?  My recommendation overall is that you reexamine your overall data structure and make sure it's doing what you think it should be doing, because the impression I get here is that there are missing elements.

Reply
  • +1
    Certified Lead Developer

    Your primary issue is that you're only defining one row in the rows: parameter of your grid.  This should instead be an array of a!gridRowLayout() objects (not just one like you currently have).  Krishna's example above has this configured correctly, for reference.  In your case I'd guess you should iterate over your ri!requestTypeRef array (using a!forEach) and define the rows that way.  Luckily this only requires a few specific edits to your current code.

    Secondly I'm a bit confused what you're trying to do while saving into serviceTypeRef or supplyTypeRef - if these each are associated with a specific "Request Type" row, where is the logical connection between them?  From your screenshot I can tell that "service type ref" has only ID and Name as distinguishing features, so what relation does each entry of this have to a specific supply type row?  My recommendation overall is that you reexamine your overall data structure and make sure it's doing what you think it should be doing, because the impression I get here is that there are missing elements.

Children