Skip to main content
Known Participant
Nov 16, 2022 10:05 AM UTC
Solved

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

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

    Inspiring
    Nov 16, 2022 11:24 AM UTC

    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
    Inspiring
    Nov 16, 2022 10:11 AM UTC

    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.

    Inspiring
    Nov 16, 2022 11:24 AM UTC

    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"
          )
        }
      )
    )

    Known Participant
    Nov 16, 2022 3:15 PM UTC

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

    mikes0011
    Brainy
    Nov 16, 2022 5:06 PM UTC

    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