Hi Everyone,
Can anyone please tell me how can I retrieve the pdf files as a link in the interface, based on the name coming from database table? The document is stored in the folder in appian.
Thank You
Discussion posts and replies are publicly visible
When you say "the pdf files", and "the folder", which ones are you referring to exactly? What name are you getting from the database - the filename? If so, which part(s)? Is there any particular reason the DB table isn't storing the Appian Doc ID instead of a "name"? That would make the process much more straightforward.
First I'd like to second Mike's suggestion of storing the document ID in the database instead of or along with the file name. File names are not unique and mechanisms to search your entire document store to retrieve them by name is not scalable and can have extremely poor performance - and you can easily run into multiple documents with the same name which can be impossible to differentiate.
There are not any functions OOTB that I know of to do this either, however the Content Tools plugin does contain a function fn!finddocumentsbyname(). This function does not utilize the document extension (name only) so you will have to do additional parsing from the return if there can be docs with different extensions. We had one older system that stored document names in the DB, a report would show a document link with each process instance, and loading the report was super painful (minutes). We eventually scripted out a conversion to doc IDs for existing processes and upgraded the process model to avoid this.
At any rate, once you have a document object you can utilize documentdownloadlink() within a variety of components to allow downloads. A forum favorite is a!richTextDisplayField due to it's flexibility:
a!localVariables( local!document: todocument(538491), a!richTextDisplayField( labelPosition: "COLLAPSED", value: { a!richTextItem( text: document(local!document,"name"), link: a!documentDownloadLink( document: local!document ) ) } ) )
Additionally our most common method is to store a folder ID in the database related to each process instance, when the documents are typically grouped - then we retrieve the list of docs via the fn!folder(docId,"documentChildren") OOTB function. In times past we have also used fn!getdocumentsfromfolder() (also part of the Content Tools plugin).
folder(516521,"documentChildren")
Yes that is correct, storing the document id in the database.
I have the id of the document in the interface as a link but the download link to retrive the document stored in the folder will be different for different documents. How can I retrieve those documents.
Did you check this?
docs.appian.com/.../Document_Link_Component.html
Could you please explain me about how to retrieve the document from the dolder? There are multiple files. What to use in the document parameter for a!documentDownloadLink( label, document, showWhen ) to get multiple files link from folder in grid layout.
You wrote that you have the IDs of the documents. Use them for the parameter "document" and you are good.
In that case you would just use a!documentDownloadLink() and point it to the document ID. I recommend doing this inside a!richTextDisplayField(), since it gives you control over other things like styling and link visibility, which don't exist in the older a!linkField().
Hope this helps
a!localVariables( local!documents: folder(tofolder(67627), "documentChildren"), local!pdfDocuments: a!flatten(tointeger(reject(rule!AG_CMN_CheckNullOrEmpty(_),a!forEach( items: local!documents, expression: a!flatten({if(document(fv!item, "extension")="PDF", fv!item, null)})))) ), a!richTextDisplayField( labelPosition: "COLLAPSED", value: if( rule!AG_CMN_CheckNullOrEmpty(local!pdfDocuments), {}, a!richTextBulletedList( items: { a!forEach( items: local!pdfDocuments, expression: a!richTextItem( text: document(fv!Item, "name"), link: a!documentDownloadLink(document: fv!Item) ) ) } ) ) ) )