Adding rows to cdt

Hi Everyone,

I am getting the cdt rows through record type using expression rule. Is it possible to add more unique rows to cdt through expression rule. If yes, can anyone please help me out?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hello  

    What do you mean by this?

    I am getting the cdt rows through record type using expression rule.

    Are you saying that you are casting the data to RecordType?

    Try out the below code. As per my understanding, You are querying data from CDT and casting it to a recordType and using it in a grid. In the same grid you want to edit or add the data and cast the data to CDT and save it using write to datastore entity. If yes, then this is the code.

    a!localVariables(
      local!data: rule!yourQueryOfCDTToRecordData(),
      local!toCDT: a!forEach(
        items: local!data,
        expression: type!CDT(
          field1:"value",
          field2:"value",
          .
          .
          fieldn:"value"
        )
      ),
      {
        a!gridLayout(
          label: "Editable Grid",
          labelPosition: "ABOVE",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell")
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE")
          },
          rows: {
            a!forEach(
              items: local!data,
              expression: {
                a!gridRowLayout(
                  contents: {
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    )
                  }
                )
              }
            )
          },
          addRowLink: a!dynamicLink(
            label: "add Row",
            value: null,
            saveInto: a!save(
              local!data,
              append(
                local!data,
                recordType!yourRecordType()
              )
            )
          ),
          selectionSaveInto: {},
          validations: {},
          shadeAlternateRows: true
        ),
        a!buttonArrayLayout(
          buttons: a!buttonWidget(saveInto: a!save(ri!myCDT, local!toCDT))
        )
      }
    )

Reply
  • 0
    Certified Senior Developer

    Hello  

    What do you mean by this?

    I am getting the cdt rows through record type using expression rule.

    Are you saying that you are casting the data to RecordType?

    Try out the below code. As per my understanding, You are querying data from CDT and casting it to a recordType and using it in a grid. In the same grid you want to edit or add the data and cast the data to CDT and save it using write to datastore entity. If yes, then this is the code.

    a!localVariables(
      local!data: rule!yourQueryOfCDTToRecordData(),
      local!toCDT: a!forEach(
        items: local!data,
        expression: type!CDT(
          field1:"value",
          field2:"value",
          .
          .
          fieldn:"value"
        )
      ),
      {
        a!gridLayout(
          label: "Editable Grid",
          labelPosition: "ABOVE",
          headerCells: {
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell"),
            a!gridLayoutHeaderCell(label: "Header Cell")
          },
          columnConfigs: {
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE"),
            a!gridLayoutColumnConfig(width: "DISTRIBUTE")
          },
          rows: {
            a!forEach(
              items: local!data,
              expression: {
                a!gridRowLayout(
                  contents: {
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    ),
                    a!textField(
                    )
                  }
                )
              }
            )
          },
          addRowLink: a!dynamicLink(
            label: "add Row",
            value: null,
            saveInto: a!save(
              local!data,
              append(
                local!data,
                recordType!yourRecordType()
              )
            )
          ),
          selectionSaveInto: {},
          validations: {},
          shadeAlternateRows: true
        ),
        a!buttonArrayLayout(
          buttons: a!buttonWidget(saveInto: a!save(ri!myCDT, local!toCDT))
        )
      }
    )

Children
No Data