I posted this a few days ago on the IBM TechXchange, but you might find it helpful here too:
https://community.ibm.com/community/user/asset-facilities/discussion/download-the-selected-attachements-at-one-go
First go to the Integration > Launch in Context application and create a new record with a name of DLSELECTED as shown below. Note that the console URL is /maximo/oslc/script/dlselected. The "dlselected" is the name of the script that we are going to create in a moment.
Go to the Application Designer and then select the application you want to add this functionality to, in my example I am using WOTRACK. Select the Add/Modify Signature Options and create a new row. Create a new row option and name it DLSELECTED, then expand the Advanced Signature Options and select "Associate to launch entry to enable launch in context" and then select the DLSELECTED launch in context record you created in the first step, then click the OK button to save.
Next, export the LIBRARY XML and update the viewattachments dialog as shown below. The table element now has selectmode="multiple" and there is a new tablecol with id 1742834229442 that allows the records to be toggled selected or not.
Then at the bottom there is a new pushbutton viewattachments_2_2 that will fire the mxevent "DLSELECTED".
<dialog id="viewattachments" label="View Attachments" savemode="ONLOAD">
<table id="viewattachments_table" inputmode="readonly" selectmode="multiple">
<tablebody id="viewattachments_tablebody" >
<tablecol id="1742834229442" type="event" mxevent="toggleselectrow" mxevent_desc="Select Row {0}" dataattribute="action" sortable="false" filterable="false" hidden="false"/>
<tablecol dataattribute="document" id="viewattachments_table_tablebody_4" label="Document" type="openurl" urlattribute="weburl"/>
<tablecol dataattribute="docinfo.description" id="viewattachments_table_tablebody_6" label="Description" sortable="false"/>
<tablecol dataattribute="doctype" id="viewattachments_table_tablebody_3" label="Document Folder"/>
<tablecol dataattribute="docversion" id="viewattachments_table_tablebody_5" label="Document Version"/>
<tablecol dataattribute="printthrulink" id="viewattachments_table_tablebody_9" label="Print"/>
<tablecol dataattribute="ownertable" id="viewattachments_table_tablebody_1" label="Application"/>
<tablecol filterable="false" hidden="false" id="viewattachments_table_tablebody_7" mxevent="linkproperties" mxevent_desc="Attachment Properties" mxevent_icon="img_information.gif" sortable="false" type="event"/>
<tablecol filterable="false" hidden="false" id="viewattachments_table_tablebody_8" mxevent="instantdelete" mxevent_desc="Delete Row" mxevent_icon="btn_delete.gif" sortable="false" type="event"/>
</tablebody>
</table>
<buttongroup id="viewattachments_2">
<pushbutton id="viewattachments_2_2" label="Download Selected" mxevent="dlselected"/>
<pushbutton default="true" id="viewattachments_2_1" label="OK" mxevent="dialogok"/>
</buttongroup>
</dialog>
After editing the file, upload it back to Maximo.
Next, go to the Security Groups application, select the security group that will have the right to download multiple attached documents. This may be the EVERYONE group, but in my case I just used the MAXADMIN group for convenience.
You may need to log out and back in for this step to take effect.
Finally, create a new automation script named DLSELECTED. This is just the script without any launch points. Note I have included the scriptConfig for this, so if you want to use the Maximo Developer Tools VS Code extension that will make this step easier.
https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy
from psdi.webclient.system.controller import BaseInstance
from java.util.zip import ZipEntry, ZipOutputStream
from java.io import File, FileInputStream
from java.lang import Byte
from java.lang.reflect import Array
def download_selected_attachments():
if "request" in globals():
# Get the HTTPServletRequest Session for the current user.
session = request.getHttpServletRequest().getSession()
currentComponent = session.getAttribute("currentcomponent")
if currentComponent is not None and isinstance(currentComponent, BaseInstance):
wcs = currentComponent.getWebClientSession()
if wcs is not None:
table = wcs.findControl("viewattachments_table")
if table is not None:
dataBean = table.getDataBean()
if dataBean is not None:
selectedAttachments = dataBean.getSelection()
if (
selectedAttachments is not None
and selectedAttachments.size() > 0
):
response = request.getHttpServletResponse()
response.setBufferSize(0)
response.setContentType("application/zip")
response.setHeader(
"content-disposition",
'attachment; filename="attachments.zip"',
)
zipOut = ZipOutputStream(response.getOutputStream())
for attachment in selectedAttachments:
file = File(attachment.getString("DOCINFO.URLNAME"))
if file.exists():
data = Array.newInstance(Byte.TYPE, file.length())
fis = FileInputStream(file)
fis.read(data)
fis.close()
fileName = (
file.getName()
.replace(".", "_")
.replace(" ", "_")
)
zipEntry = ZipEntry(fileName)
zipOut.putNextEntry(zipEntry)
zipOut.write(data, 0, len(data))
zipOut.closeEntry()
zipOut.flush()
zipOut.close()
response.flushBuffer()
else:
return "No attachments selected to download."
else:
return "The viewattachments_table control does not have a data bean, cannot find the files to download."
else:
return "The viewattachments_table control is not available, cannot find the files to download."
else:
return "The WebClientSession is not available, cannot find the files to download."
else:
return 'The servlet session does not contain a "currentcomponent" attribute, cannot find the files to download.'
else:
return "The DLSELECTED script was called from a non-HTTP request context."
responseBody = str(download_selected_attachments())
scriptConfig = """{
"autoscript": "DLSELECTED",
"description": "Download selected attachments",
"version": "1.0.0",
"active": true,
"logLevel": "ERROR"
}"""
Now go to work order tracking and click the Attachments link. You should see something like the following:
Click the Download Selected button and it will zip the selected files and then download them. Please note that this does not work with S3 storage, but if you need that it isn't too much more work to work with that instead of simple file storage.
If you have questions please feel free to reach out.