Skip to main content
November 16, 2022
Solved

How to upload a file from a form and save to database

  • November 16, 2022
  • 10 replies
  • 0 views

 I want to upload the file and save it into the database in integer form. How can I do it?

    Best answer by pavitrad2763

    Hi shrutij9485,

    Please try below code. It will save the document in documents folder and document ID to database table

    a!formLayout(
      label: "Form",
      contents: {
        a!cardLayout(
          contents: {
            a!fileUploadField(
              label: "File Upload",
              labelPosition: "ABOVE",
              target: cons!PDS_DOCUMENT_FOLDER,
              value: ri!Document.documentId,
              saveInto: a!save(ri!Document.documentId, save!value),
              validations: {}
            )
          },
          height: "AUTO",
          style: "NONE",
          marginBelow: "STANDARD"
        )
      },
      buttons: a!buttonLayout(
        primaryButtons: {
          a!buttonWidgetSubmit(
            label: "Submit",
            saveInto: a!writeToDataStoreEntity(cons!PDS_DATASTORE_DOCUMENT_CONSTANTS,
            ri!Document,
            "Success",
            ""),
            submit: true,
            style: "PRIMARY"
          )
        }
      )
    )

    10 replies

    viraty527193
    November 16, 2022

    Hi Shruti,

    File_Upload_Component

    Please go through the documentation to see how you can upload a file, once you upload it you will get a document Id in the variable which you have passed into the saveInto parameter, you can save it in a CDT field which can be used to write into the database table.

    Below is the link of 'how you can write values to the database'

    Write_to_Data_Store_Entity_Smart_Service

    Hope it helps, happy to discuss further.

    November 16, 2022

    Hi shrutij9485,

    Please try below code. It will save the document in documents folder and document ID to database table

    a!formLayout(
      label: "Form",
      contents: {
        a!cardLayout(
          contents: {
            a!fileUploadField(
              label: "File Upload",
              labelPosition: "ABOVE",
              target: cons!PDS_DOCUMENT_FOLDER,
              value: ri!Document.documentId,
              saveInto: a!save(ri!Document.documentId, save!value),
              validations: {}
            )
          },
          height: "AUTO",
          style: "NONE",
          marginBelow: "STANDARD"
        )
      },
      buttons: a!buttonLayout(
        primaryButtons: {
          a!buttonWidgetSubmit(
            label: "Submit",
            saveInto: a!writeToDataStoreEntity(cons!PDS_DATASTORE_DOCUMENT_CONSTANTS,
            ri!Document,
            "Success",
            ""),
            submit: true,
            style: "PRIMARY"
          )
        }
      )
    )

    November 16, 2022

    I tried this solution but in process model itis showing that data cannot be written in database

    mikes0011
    Brainy
    November 16, 2022

    The above solution is generally correct - if you're having further issues then you'll need to provide more detail with respect to exactly what you're trying and exaclty what error you're receiving in the process instance.

    The Expression Guru