Hi,
I have list of files on UI which i want to download in zip folder.
What is the way out to implement this approach.
Kindly share me any code or any approach on this ?
Discussion posts and replies are publicly visible
Below plugin will help
https://community.appian.com/b/appmarket/posts/document-zipper
You can also have a look at - https://community.appian.com/b/appmarket/posts/add-documents-to-zip.
How you are passing doc details to PM.
I mean below details you are passing from Interface or plugging at PM level.
I think so Base Doc/Save In folder/Document Path is optional here rest is mandatory.
Why do we need to pass path here if required as i just want to bundle out all my files n zip them in one folder. i don't want to save anywhere.
Kindly share some inputs on that.
Why do we need this Documents Path as we are storing document id in DB and getting back by using some function from Appian portal. Then which path we need to refer here.
sauravk said:Why do we need this Documents Path
The "Document Paths" input will determine the path and filename for the matching document from the "Documents to Add" array within the generated ZIP file only. Therefore if you only want the documents to be at the "root level" of the zip file (the most common way), you would simply pass an array of the filenames. This needs to include the file extension, i.e. {"file1.docx", "file2.docx"}, not {"file1", "file2"}.
And for further clarification, if you wanted the files to be in a folder off the root of the zip file, let's say a top level folder called "Documents", you would pass this array: {"Documents\file1.docx", "Documents\file2.docx"}
sauravk said:I think so Base Doc/Save In folder/Document Path is optional here
Per my best understanding (and supported by myself using it successfully in the past):
If "Create New Document" is set to TRUE, then you must provide "New Document Name" and "Save In Folder".
If "Create New Document" is set to FALSE, then "Existing Document" is required - the files will be added to the "Base Document" zip file (if provided) and the changed file will become a new version on the same file ID.
Thanks Mike for your inputs. Now I have followed your approach but having facing some exception. Sharing code snippet what I have done so far.
secondaryButtons: a!buttonWidget( label: "Download", icon: "download", saveInto: a!startProcess( processModel: cons!DOC_ZIP_PROCESS, processParameters: { documents: difference(a!forEach( items: index( local!dataSet.data, "docId", null ), expression: if( or( isnull( fv!item ), not( isobjectexists( "Document", tointeger( fv!item ) ) ) ), "", document( tointeger( fv!item ), "name" ) ) ),""), documentPath: difference(a!forEach( items: index( local!dataSet.data, "docId", null ), expression: if( or( isnull( fv!item ), not( isobjectexists( "Document", tointeger( fv!item ) ) ) ), "", document( tointeger( fv!item ), "name" ) ) ),""), zipName: tostring( "Test Doc" ) & "File_.zip", } )
Base Document - Blank
Create New Document : True
New Document Name-=pv!zipName
New Document Desc : Blank
Save In Folder - Temporary Documents(Selected folder via search browser window)
Existing document- Blank
Document to Add- =pv!documents
Documents Path- =pv!documentPath
In Document to Add and Documents Path I am passing same content . I am passing list of documents name as you suggested. But I am getting below error now.
Where I am missing. Now in documents,documentPath in both variable there is no null data after using difference() function. I am not understanding where this null coming now.
I have tried to change document n documentPath variable but now new error is poping up.
documents:12754,
documentPath:document(12754, "name"),
I am not sure what i am passing in document n documentPath is correct or not. I feel so error is around this variable only.
And then tried with below parameters also.
document:- reject(fn!isnull, a!forEach( items: index( local!dataset.data, "docId", null ), expression: if( or( isnull( fv!item ), not( isobjectexists( "Document", tointeger( fv!item ) ) ) ), null, document( tointeger( fv!item ), "name" ) ) )), documentPath:- reject(fn!isnull, difference(a!forEach( items: index( local!datasubset.data, "docId", null ), expression: if( or( isnull( fv!item ), not( isobjectexists( "Document", tointeger( fv!item ) ) ) ), "", document( tointeger( fv!item ), "name" ) ) ),"")),
But getting below error.
I'm not sure if this is what's causing your error, but you should be aware that the smart service expects you to provide the full document name as I mentioned before, which is the name + extension (so far your code just passes the name). For example,
document(fv!item, "name") & "." & "document(fv!item, "extension")
It might still work without the extensions, but your resulting zip file will end up with files without extensions which you probably don't want.
Other than this, all I can suggest is monitor a running instance and make sure your PVs have populated correctly - most importantly, pv!documents (should be either an array of document or an array of integer, the node will correctly typecast what it needs from either of these), and pv!documentPath (this needs to also be an array of course, at the very least containing the full name of each document in the array).
Hi Mike,
As i have shared my code in that i passing documents(array of doc id) and now i changed documentpath (array of name). But still java.lang.ArrayIndexOutOfBoundsException: 0
But if i change documents value to same as documentpath then i get java.lang.NullPointerException: Null Arguments are Invalid
It means documents(array of doc id) is correct format i feel so as per exception.
Why this ArrayIndexOutOfBoundsException this coming ?
I'm not sure what the source of that error is - the only thing I can suggest is to verify that your inputs are being entered correctly and correctly populated within the process instance. Can you post a screenshot of the values of "documents" and "documentPath" from within a process instance? It sounds almost as if one of the required values for the node is actually set as something invalid within the process instance (such as 0, or an empty set).
documents:-1245;1232;4567
documentPath:-test-sample.csv.2014-06-13; test-sample.csv.2014-06-25; test-sample.csv.2014-06-13;
Exact these values are going to PM.
I can't tell for sure until you post a screenshot, but it looks as if your "documentPath" array has a null entry at the end there. I expect that might cause unexpected issues when you feed the arrays into the zip file node, as it expects 2 arrays of the same length (and the document path values would never be null).
There is no null entry in this. I have verified with count() function . I have simply printed on my interface in text field. Even i have used reject function also to remove null n blank entires. So i am sure on that part.
Please provide a screnshot of this when you can, as there's not much more I can think of to troubleshoot without it. For example, here's mine:
you were absolutely correct.
But dono how its possible.
I think you need to go back to the expression you're using to pull your doc IDs and troubleshoot more. Perhaps comment out the startProcess() call temporarily and just write the docIds and docNames into local variables which you then display in a debug field on your interface.
If you see the code. It is returning values but i feel so type is not type of Document that's why in PM its coming null values.Otherwise on interface in textField its is returning list of id's.Anyways i got the pointer to more trouble shoot this. Thanks for pushing your inputs in this issue.
Now both variables are getting populate at PM side also but error is still same java.lang.ArrayIndexOutOfBoundsException: 0