How to connect a data store to a record

Hi! I used to work with records, uploading the data based on a manual task in an interface (user introduces parameters and the record updates the info). However, I had to use a data store entity for an editable grid programmation, and I dont know if there is a chance to upload the record based on the data store entity. Thanks!

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    You could write an expression rule that takes the CDT as an input and returns the Record Type with all the fields mapped appropriately.

    Ideally, you would be using Record Types everywhere to avoid having to do this.

  • 0
    Certified Lead Developer

    Why do you have to use a data store for an editable grid? This is confusing ...

  • Thanks for your answer! The fact is that I had to make an editable grid with the function append in order to add new rows. I followed a tutorial and they used data store in order to make the local variables. I would prefer to do everything only with records, as you said before, but I´m new in appian and, even though I tried to substitute everything and use a record, I have problems in some lines, specially in the function append. 

    How could I substitute the array for the record in my code? Any help would be useful, thank you so much!

    I show you the editable grid code so you can understand my problem:

     

    a!localVariables(
    local!gridDataType: 'type!{urn:com:appian:types:PTPP}PTPP_INVOICE_LINES'(),

    a!formLayout(
    label: "Invoice Detail",
    contents: {
    a!gridLayout(
    label: "Invoice Lines Information",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Purchase Order"),
    a!gridLayoutHeaderCell(label: "Date"),
    a!gridLayoutHeaderCell(label: "Total Value"),
    a!gridLayoutHeaderCell(label: "Material"),
    a!gridLayoutHeaderCell(label: "Supplier"),
    a!gridLayoutHeaderCell(label: "")
    },
    columnConfigs: {
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"ICON")
    },
    rows: {
    a!forEach(
    items: ri!Array_InvoiceLines,
    expression: a!gridRowLayout(
    contents: {
    a!textField(value:fv!item.idOrden, saveInto: fv!item.idOrden),
    a!textField(value:fv!item.fechaOrden, saveInto: fv!item.fechaOrden),
    a!textField(value:fv!item.totalOrden, saveInto: fv!item.totalOrden),
    a!textField(value:fv!item.material, saveInto: fv!item.material),
    a!textField(value:fv!item.idProveedor, saveInto: fv!item.idProveedor),
    a!richTextDisplayField(
    value: a!richTextIcon(
    icon: "times-circle",
    color: "NEGATIVE",
    link: a!dynamicLink(
    saveinto: a!save(
    target: ri!Array_InvoiceLines, value: remove(
    ri!Array_InvoiceLines, fv!index
    )
    )
    )
    )
    )
    }
    )
    )

    },
    selectionSaveInto: {},
    addRowLink: a!dynamicLink(
    label: "Add new Invoice Line",
    saveinto: a!save(target: ri!Array_InvoiceLines, append(ri!Array_InvoiceLines, local!gridDataType))
    ),
    validations: {},
    shadeAlternateRows: true
    )
    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit ",
    submit: true,
    style: "PRIMARY",
    validate: true
    )
    },
    secondaryButtons: {
    a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: ri!cancel,
    submit: true,
    style: "NORMAL",
    validate: false
    )
    }
    )
    )
    )

  • When I tried to use records, an error appears (cannot index null values). It´s true that I created my record from scratch and it´s empty, but I don´t think this should be a problem. If it is not an inconvenience, could you tell me what is wrong with my code ? I´m posting images and the real code, ( "PTPP_Invoice_Lines" is my empty record, I want the user to be able to add new rows of information, and update the record) and an image of the error too 

    Next, error that happens when I try to add a new row (using records in the code)

    Then, my code:


    a!formLayout(
    label: "Invoice Detail",
    contents: {
    a!gridLayout(
    label: "Invoice Lines Information",
    labelPosition: "ABOVE",
    headerCells: {
    a!gridLayoutHeaderCell(label: "Purchase Order"),
    a!gridLayoutHeaderCell(label: "Date"),
    a!gridLayoutHeaderCell(label: "Total Value"),
    a!gridLayoutHeaderCell(label: "Material"),
    a!gridLayoutHeaderCell(label: "Supplier"),
    a!gridLayoutHeaderCell(label: "")
    },
    columnConfigs: {
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
    a!gridLayoutColumnConfig(width:"ICON")
    },
    rows: {
    a!forEach(
    items: ri!InvoiceLines,
    expression: a!gridRowLayout(
    contents: {
    a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden']),
    a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{25003162-d3d0-4466-86f8-471cb1e37589}fecha_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{25003162-d3d0-4466-86f8-471cb1e37589}fecha_orden']),
    a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{c228ed4c-21cb-4af4-a313-88f26e7874da}total_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{c228ed4c-21cb-4af4-a313-88f26e7874da}total_orden']),
    a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{5f4060f6-827d-41b5-88e7-0328ec1309bc}Material'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{5f4060f6-827d-41b5-88e7-0328ec1309bc}Material']),
    a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{d9317466-7426-47af-bd64-22a998c636e6}id_proveedor'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{d9317466-7426-47af-bd64-22a998c636e6}id_proveedor']),
    a!richTextDisplayField(
    value: a!richTextIcon(
    icon: "times-circle",
    link: a!dynamicLink(
    saveinto: a!save(
    target: ri!InvoiceLines, value: remove(
    ri!InvoiceLines, fv!index
    )
    )
    ),
    color: "NEGATIVE"
    )
    )
    }
    )
    )

    },
    selectionSaveInto: {},
    addRowLink: a!dynamicLink(
    label: "Add new Invoice Line",
    saveinto: a!save(target: ri!InvoiceLines, append(ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden'], ri!InvoiceLines))
    ),
    validations: {},
    shadeAlternateRows: true
    )
    },
    buttons: a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Submit ",
    submit: true,
    style: "PRIMARY",
    validate: true
    )
    },
    secondaryButtons: {
    a!buttonWidget(
    label: "Cancel",
    value: true,
    saveInto: ri!cancel,
    submit: true,
    style: "NORMAL",
    validate: false
    )
    }
    )
    )

  • a!localVariables(
      local!gridDataType: 'type!{urn:com:appian:types:PTPP}PTPP_INVOICE_LINES'(),
    
      a!formLayout(
        label: "Invoice Detail",
        contents: {
          a!gridLayout(
            label: "Invoice Lines Information",
            labelPosition: "ABOVE",
            headerCells: {
              a!gridLayoutHeaderCell(label: "Purchase Order"),
              a!gridLayoutHeaderCell(label: "Date"),
              a!gridLayoutHeaderCell(label: "Total Value"),
              a!gridLayoutHeaderCell(label: "Material"),
              a!gridLayoutHeaderCell(label: "Supplier"),
              a!gridLayoutHeaderCell(label: "")
            },
            columnConfigs: {
              a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
              a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
              a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
              a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
              a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
              a!gridLayoutColumnConfig(width:"ICON")
            },
            rows: {
              a!forEach(
                items: ri!Array_InvoiceLines,
                expression: a!gridRowLayout(
                  contents: {
                    a!textField(value:fv!item.idOrden, saveInto: fv!item.idOrden),
                    a!textField(value:fv!item.fechaOrden, saveInto: fv!item.fechaOrden),
                    a!textField(value:fv!item.totalOrden, saveInto: fv!item.totalOrden),
                    a!textField(value:fv!item.material, saveInto: fv!item.material),
                    a!textField(value:fv!item.idProveedor, saveInto: fv!item.idProveedor),
                    a!richTextDisplayField(
                      value: a!richTextIcon(
                        icon: "times-circle",
                        color: "NEGATIVE",
                        link: a!dynamicLink(
                          saveinto: a!save(
                            target: ri!Array_InvoiceLines, value: remove(
                              ri!Array_InvoiceLines, fv!index
                            )
                          )
                        )
                      )
                    )
                  }
                )
              )
    
            },
            selectionSaveInto: {},
            addRowLink: a!dynamicLink(
              label: "Add new Invoice Line",
              saveinto: a!save(target: ri!Array_InvoiceLines, append(ri!Array_InvoiceLines, local!gridDataType))
            ),
            validations: {},
            shadeAlternateRows: true
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit ",
              submit: true,
              style: "PRIMARY",
              validate: true
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: ri!cancel,
              submit: true,
              style: "NORMAL",
              validate: false
            )
          }
        )
      )
    )
        
        

    I also include images of the code. Thanks!

    With this code, I am able to add rows and put values into it, but I´m not able to upload the data in my record after that. I repplied in the next message (Stefan Helzle) and added the new code using records, in which I have error

    Thank you again, best regards

  •       a!formLayout(
            label: "Invoice Detail",
            contents: {
              a!gridLayout(
                label: "Invoice Lines Information",
                labelPosition: "ABOVE",
                headerCells: {
                  a!gridLayoutHeaderCell(label: "Purchase Order"),
                  a!gridLayoutHeaderCell(label: "Date"),
                  a!gridLayoutHeaderCell(label: "Total Value"),
                  a!gridLayoutHeaderCell(label: "Material"),
                  a!gridLayoutHeaderCell(label: "Supplier"),
                  a!gridLayoutHeaderCell(label: "")
                },
                columnConfigs: {
                  a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
                  a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
                  a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
                  a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
                  a!gridLayoutColumnConfig(width:"DISTRIBUTE"),
                  a!gridLayoutColumnConfig(width:"ICON")
                },
                rows: {
                  a!forEach(
                    items: ri!InvoiceLines,
                    expression: a!gridRowLayout(
                      contents: {
                        a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden']),
                        a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{25003162-d3d0-4466-86f8-471cb1e37589}fecha_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{25003162-d3d0-4466-86f8-471cb1e37589}fecha_orden']),
                        a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{c228ed4c-21cb-4af4-a313-88f26e7874da}total_orden'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{c228ed4c-21cb-4af4-a313-88f26e7874da}total_orden']),
                        a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{5f4060f6-827d-41b5-88e7-0328ec1309bc}Material'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{5f4060f6-827d-41b5-88e7-0328ec1309bc}Material']),
                        a!textField(value:ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{d9317466-7426-47af-bd64-22a998c636e6}id_proveedor'], saveInto: ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{d9317466-7426-47af-bd64-22a998c636e6}id_proveedor']),
                        a!richTextDisplayField(
                          value: a!richTextIcon(
                            icon: "times-circle",
                            link: a!dynamicLink(
                              saveinto: a!save(
                                target: ri!InvoiceLines, value: remove(
                                  ri!InvoiceLines, fv!index
                                )
                              )
                            ),
                            color: "NEGATIVE"
                          )
                        )
                      }
                    )
                  )
    
                },
                selectionSaveInto: {},
                addRowLink: a!dynamicLink(
                  label: "Add new Invoice Line",
                  saveinto: a!save(target: ri!InvoiceLines, append(ri!InvoiceLines['recordType!{d269796e-dcd7-46b6-8ecf-55ed16bf54a1}PTPP Invoice Lines.fields.{ab97d392-b365-425a-a0e5-116da756c87a}id_orden'], ri!InvoiceLines))
                ),
                validations: {},
                shadeAlternateRows: true
              )
            },
            buttons: a!buttonLayout(
              primaryButtons: {
                a!buttonWidget(
                  label: "Submit ",
                  submit: true,
                  style: "PRIMARY",
                  validate: true
                )
              },
              secondaryButtons: {
                a!buttonWidget(
                  label: "Cancel",
                  value: true,
                  saveInto: ri!cancel,
                  submit: true,
                  style: "NORMAL",
                  validate: false
                )
              }
            )
      )
      

    I include the code with better format. Thanks!

  • 0
    Certified Lead Developer
    in reply to carlosp5114

    This

    a!textField(value:ri!InvoiceLines

    must become

    a!textField(value:fv!item

    That's why you use the foreach.

    www.youtube.com/watch

  • Thanks for your answer! I followed step by step the video, but I have a trouble when I add the record field after the fv!item. The video creator could create it and had no trouble

  • 0
    Certified Lead Developer
    in reply to carlosp5114

    I do not see how this error is triggered.