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
  • The way you have it set up now, you have added a single grid row, which means that the grid will always have exactly one row. However, you mentioned that you wanted to be able to add up to 5 rows depending on the data.

    In order to set that up, you will need to use a!forEach() to iterate over the list of items. See this recipe for how to set up the a!forEach() for your grid rows: Add, Edit, and Remove data in an inline editable grid.

    As far as saving into multiple CDTs, you will need to make sure that each CDT has the same number of items. You will notice in the recipe that an add row link appends a new item to the CDT used; you will need to do this for all of your CDTs to ensure they are the same length array.

Reply
  • The way you have it set up now, you have added a single grid row, which means that the grid will always have exactly one row. However, you mentioned that you wanted to be able to add up to 5 rows depending on the data.

    In order to set that up, you will need to use a!forEach() to iterate over the list of items. See this recipe for how to set up the a!forEach() for your grid rows: Add, Edit, and Remove data in an inline editable grid.

    As far as saving into multiple CDTs, you will need to make sure that each CDT has the same number of items. You will notice in the recipe that an add row link appends a new item to the CDT used; you will need to do this for all of your CDTs to ensure they are the same length array.

Children