Hi, I have paging grid to show all documents and I want to create a

Hi,

I have paging grid to show all documents and I want to create a link to the document for download. There is a link created but not to the document. Any suggestions on expression so i can get the link to document?
Expression:
a!gridTextColumn(
label: "Name",
field: "appiandocumentid",
data: local!datasubset.data.name,
links:apply(a!documentDownloadLink(document:_), index(local!datasubset.data, "appiandocumentid", {}))
),

OriginalPostID-173948

OriginalPostID-173948

  Discussion posts and replies are publicly visible

  • Your code seems to be OK. How is the datasubset looking? Do the document IDs point to the right file? Have you tried printing your data to screen to see what is actually in it?
  • Can you please check if the name of the field in the cdt of the datasubset is "appiandocumentid" not the field name of the grid column?
  • I assume you are not storing documentId properly in DB. Doc Id which you get after uploading doc is less than 1 by actual doc ID,
    I mean If you upload a doc and if its appian ID is 2247 , process model gives you 2246, so while saving doc id in DB add '1' to it and save, so retrival will not give error and you'll get document in download link.
    If you have saved correct doc ID and not able to retrive, then use todocument() and check.
    apply(a!documentDownloadLink(document:_), todocument(index(local!datasubset.data, "appiandocumentid", {})))
  • That is very dangerous. A document uploaded in a SAIL form is saved to Appian DMS on submit of the form and the CORRECT id is saved to the AC variable of the user input task. When you use this id in the output definition of the task it is fine and should not be increased.

    The problem with the document ids is with trying to access the id inside the form without submitting. This can be circumvented using some hacks but is risky.
  • Stefan, I remember there was post to download document without form submit, But I don't know exact URL,
    And Doc ID in ac variable in actual docId-1, PFA


  • The temporary document ID stored in SAIL before form submission is not guaranteed to be actual docId-1. If you have more than one document upload on a form, this will change. The only way I know of to guarantee that you get the document ID correctly is to save it off as a form input and utilize it as an AC parameter into the form via the process model.
  • In addition, if you have a document as a part of a CDT, it will not update the document ID correctly. You need to have the documents as separate inputs to the form, and then use a script task afterwards to map the document(s) to the proper parts of the CDT. You might be able to do it on the output of the AC within the user input task, but I have not personally tried it.
  • Working Code:
    a!gridTextColumn(
                                                                                              label: "Name",
                                                                                              field: "appiandocumentid",
                                                                                              data: property(local!datasubset.data, "name", {}),
                                                                                              links: {
                                                                                               apply(
                                                                                               a!documentDownloadLink(document:_),
                                                                                               property(local!datasubset.data, "appianDocumentId", {})
                                                                                               )
                                                                                              }
                                                                                    )