Replace existing documents

Certified Associate Developer

Hello everyone,

I’m working with an interface grid that is prepopulated with different documents. There's also an "Add New" button that allows users to upload additional documents to the grid.

Requirement:

  • Users should be able to upload new documents.
  • They should also have the ability to replace the prepopulated documents with new ones if they find an issue.
  • When a document is re-uploaded (i.e., replaced), the old document should be replaced with new one, and not saved. Essentially, we want to fully replace the old document with the new one.

I’ve read in previous posts that the target attribute on the a!fileUploadField component, when set to a folder, creates a new document in that folder. If set to a document, it’s supposed to replace the existing document by creating a new version.

However, I’m encountering issues with this approach. Here’s the code I’m using:

a!fileUploadField(
                  target: if(
                    rule!APN_isEmpty(fv!item.id),
                    tofolder(cons!ABG_DOCUMENTS_FOLDER),
                    local!priparedDocuments[fv!index].appianDocumentId
                  ),

The logic is:

  • If fv!item.id is empty (i.e., the document doesn’t exist yet—this applies to new documents added via the "Add New" button), save the file in the specified folder.
  • If the document already exists, point to the document ID to create a new version.

Here, local!preparedDocuments is a CDT that holds document info, similar to a database representation of documents, and appianDocumentId refers to the document ID in Appian.

What's happening:

1) For newly added documents everything works OK, they appear in folder and can be downloaded

2) However, when I try to replace a pre-existing document, the old document still exists, and the new one doesn’t seem to inherit the folder (its parent is shown as [Not Visible]). As a result, the new document cannot be downloaded.

Question:

Why is this happening? Shouldn’t setting the target to the document ID in a!fileUploadField replace the old document with the new one while keeping it in the same folder as the original?

  Discussion posts and replies are publicly visible

Parents Reply Children
No Data