Is there any way to pre-populate documents in file upload field?

Requirement: Suppose if there are 10 rows in an editable grid of which one column is file upload file. If I upload a document in any of the rows for the first time, the file upload fields of other rows needs to be populated with the same document uploaded. After that whenever a document is updated in any of the rows, the new document should be saved. Kindly suggest a way. TIA

  Discussion posts and replies are publicly visible

Parents
  • Hi  please find the below code

    Hope this will help you

    load(
      local!employees: {{firstName: "John"},{firstName: "Michael"},{firstName: "Mary"},},
      local!doc: rule!APN_generateRepeatedValueForArrayLength(
        local!employees,
        todocument(
          null
        )
      ),
      a!formLayout(
        contents: {
          a!sectionLayout(
            contents: {
              a!gridLayout(
                totalCount: count(
                  local!employees
                ),
                headerCells: {
                  a!gridLayoutHeaderCell(
                    label: "First Name"
                  )
                },
                columnConfigs: {
                  a!gridLayoutColumnConfig(
                    width: "DISTRIBUTE",
                    weight: 3
                  )
                },
                rows: a!forEach(
                  items: local!employees,
                  expression: a!gridRowLayout(
                    contents: {
                      a!fileUploadField(
                        maxSelections: 1,
                        value: local!doc[fv!index],
                        saveInto: if(
                          rule!APN_isEmpty(
                            local!doc
                          ),
                          a!forEach(
                            items: local!doc,
                            expression: a!save(
                              local!doc[fv!index],
                              save!value
                            )
                          ),
                          local!doc[fv!index]
                        )
                      )
                    }
                  )
                )
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Button",
              saveInto: {
                a!save(
                  ri!doc,
                  local!doc
                )
              },
              style: "NORMAL"
            )
          },
          secondaryButtons: {}
        )
      )
    )

Reply
  • Hi  please find the below code

    Hope this will help you

    load(
      local!employees: {{firstName: "John"},{firstName: "Michael"},{firstName: "Mary"},},
      local!doc: rule!APN_generateRepeatedValueForArrayLength(
        local!employees,
        todocument(
          null
        )
      ),
      a!formLayout(
        contents: {
          a!sectionLayout(
            contents: {
              a!gridLayout(
                totalCount: count(
                  local!employees
                ),
                headerCells: {
                  a!gridLayoutHeaderCell(
                    label: "First Name"
                  )
                },
                columnConfigs: {
                  a!gridLayoutColumnConfig(
                    width: "DISTRIBUTE",
                    weight: 3
                  )
                },
                rows: a!forEach(
                  items: local!employees,
                  expression: a!gridRowLayout(
                    contents: {
                      a!fileUploadField(
                        maxSelections: 1,
                        value: local!doc[fv!index],
                        saveInto: if(
                          rule!APN_isEmpty(
                            local!doc
                          ),
                          a!forEach(
                            items: local!doc,
                            expression: a!save(
                              local!doc[fv!index],
                              save!value
                            )
                          ),
                          local!doc[fv!index]
                        )
                      )
                    }
                  )
                )
              )
            }
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Button",
              saveInto: {
                a!save(
                  ri!doc,
                  local!doc
                )
              },
              style: "NORMAL"
            )
          },
          secondaryButtons: {}
        )
      )
    )

Children
  • Thanks for suggesting this approach. I proceeded with this. But I face an issue when I update a document in any of the rows before submitting the form, the auto populated documents in other rows are not getting saved. This is because while auto populating, temporary document id pointing to the first document we upload remains same for the auto populated documents and so on updating any row , we need to remove the earlier uploaded document and then we need to upload a new document. This results in deletion of temporary document id and thereby all the auto populated documents are not getting saved. Kindly let me know how to fix this.