Maximo

 View Only
  • 1.  Download the Selected Attachements at One Go!

    Posted Fri March 07, 2025 06:16 AM

    Hi All,

    I have a requirement to select the records in the View attachments and needs the records to be downloaded. 

    Can anyone advise on how it can be done?

    It will be really helpful if any references are shared.

    Thanks....



    ------------------------------
    Chaitanya Kumar R
    ------------------------------


  • 2.  RE: Download the Selected Attachements at One Go!

    Posted Mon March 10, 2025 04:19 AM

    Hi Chaitanya,

    I was thinking that you may try to implement additional UI action (ref. UI Bean Scripting or Custom Button Action) calling automation script which would call (ref. com.ibm.tivoli.maximo.script.ScriptService#openURL) another REST API automation script responsible for getting the desired attachments content, ZIPing it and returning as one archive (ref. similar technique as described in the Bulk Export of Maximo Message Tracking Data article).



    ------------------------------
    Andrzej Więcław
    Maximo Technical SME
    ZNAPZ B.V.
    Wrocław, Poland
    ------------------------------



  • 3.  RE: Download the Selected Attachements at One Go!

    Posted Mon March 10, 2025 06:36 AM

    Hi Andrzej,

    Thank you for your Prompt Response and reference articles.

    The references you have shared are for the MAS. Can we achieve the same functionality for Selecting and Downloading the multiple attachments in the MAM 7.6 as well.

    Thanks.



    ------------------------------
    Chaitanya Kumar R
    ------------------------------



  • 4.  RE: Download the Selected Attachements at One Go!

    Posted Mon March 10, 2025 07:03 AM

    Hi Chaitanya,

    only UI Bean Scripting is strictly limited to MAS Manage. Other mentioned techniques are available in Maximo EAM as well.



    ------------------------------
    Andrzej Więcław
    Maximo Technical SME
    ZNAPZ B.V.
    Wrocław, Poland
    ------------------------------



  • 5.  RE: Download the Selected Attachements at One Go!

    Posted Thu March 13, 2025 06:03 AM
    Edited by Sankar Ganesh V S Tue March 18, 2025 11:54 AM

    Hi Chaitanya,

    There are jython libraries to zip and download the files. but need to be tested in Automation script.
    https://www.baeldung.com/java-compress-and-uncompress
    This example in Java can be modified for jython, without additional libraries for an auto script.

    For adding dialog,

    • Modify or clone the View attachments dialog
    • Add a checkbox in the dialog to select the documents.

    Type: Event

    Event: toggleselectrow

    • Add a 'Download' custom action button at the footer of dialog
    • Create an action launch point for the button and write below code
     
    #Get the selection of documents from ticked checkboxes
    session=service.webclientsession()
    docTable=session.getDataBean("<dialog_id>")
    docVector=docTable.getSelection()
    
    
    #Add them to a filePath    
    filePaths=[]
    for doc in docVector:
        file=doc.getString("URLNAME")
        filePaths.append(file)

    We could further extend the script with any of below option

    • Zip the files and download
      (OR)
    • Send as attachments to email.


    Thanks!
    ------------------------------
    Sankar Ganesh V S
    Technical Consultant
    DXC Technology
    ------------------------------



  • 6.  RE: Download the Selected Attachements at One Go!

    Posted Sun March 23, 2025 11:28 PM
    Edited by Sankar Ganesh V S Mon March 24, 2025 09:22 PM

    Here is the updated script to compess(zip) files and download to specified path.

    from psdi.util import MXApplicationException;
    from java.io import FileOutputStream;
    from java.io import FileInputStream;
    from java.nio.file import Paths;
    from java.nio.file import Files;
    from java.util.zip import ZipOutputStream;
    from java.util.zip import ZipEntry;
    from java.io import File;
    
    if launchPoint=='<>':
        session=service.webclientsession()
        docTable=session.getDataBean("<dialog_id>")
        docVector=docTable.getSelection()
        
        filePaths=[]
        for doc in docVector:
            file=doc.getString("URLNAME")
            filePaths.append(file)
        
        downLoadPath="C:\\Users\\Public\\Downloads\\";
        fullPath=downLoadPath+"<FileName>.zip";
        fos = FileOutputStream(fullPath);
        zipOut = ZipOutputStream(fos);
      
        try:
            for filePath in filePaths:
                fileToZip = File(filePath);
                fis = FileInputStream(fileToZip);
                zipEntry = ZipEntry(fileToZip.getName());
                zipOut.putNextEntry(zipEntry);
                bytes = Files.readAllBytes(Paths.get(filePath));
                zipOut.write(bytes, 0, len(bytes));
                fis.close();
            zipOut.close();
            fos.close();
            print ("Compressed the Files to " +str(fullPath));        
    																   
        except MXApplicationException as me:
            print ("Maximo Error : " + str(e));
        except Exception as e :
            print ("Error : " + str(e));
    												  



    ------------------------------
    Sankar Ganesh V S
    Technical Consultant
    DXC Technology
    ------------------------------



  • 7.  RE: Download the Selected Attachements at One Go!

    Posted Mon March 24, 2025 04:27 PM
    Edited by Jason VenHuizen Mon March 24, 2025 04:28 PM

    I have reworked Sankar's solution to be more generally useful and hopefully with more context.

    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.



    ------------------------------
    Jason VenHuizen
    Sharptree
    https://sharptree.io
    https://opqo.io
    ------------------------------