BPM, Workflow, and Case

BPM, Workflow, and Case

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Delete all files associate with process instance.

    Posted Thu October 08, 2020 01:53 PM
    Hi all,

    Client is asking for a way to delete files associated with process instance. I know that the BPM document List has allow delete option, but we want to automate this. Can we do this with JavaScript?

    What we want to do is to clean up the folder of the process before they open a task.

    Thanks!

    ------------------------------
    Ivan Martinez Villegas
    ------------------------------


  • 2.  RE: Delete all files associate with process instance.

    Posted Thu October 08, 2020 01:59 PM
    Edited by Amit Rathod Thu October 08, 2020 02:01 PM

    Question on this
    1. Is document have user defined properties associated with it or just instance id you are using to differentiate documents?
    2. Which Content Management System you have used as well? Any Folder Structure you are following for documents ?


    ------------------------------
    Amit Rathod
    Pune
    ------------------------------



  • 3.  RE: Delete all files associate with process instance.

    Posted Thu October 08, 2020 03:18 PM
    Not sure about Java script. For Add document there is java script but for delete I am not sure.
    Though there are two option which I can think of
    1. You can use either OOB content management component to delete 
    2. Rest CALL using java script.


    ------------------------------
    Amit Rathod
    Pune
    ------------------------------



  • 4.  RE: Delete all files associate with process instance.
    Best Answer

    Posted Sun October 11, 2020 09:33 PM
    Edited by Ivan Martinez Villegas Mon December 14, 2020 08:17 AM
    HI Ivan,

    That is do-able. My suggestion is to create a managed UI tool for it so you can search instance and delete documents anytime you want. Also, I don't think you should delete all docs associated to an instance because you may delete docs from other tasks that are still active. Best approach is to assign identifying properties to the documents every time you upload.  

    So in document list or file dropzone, bind a NameValuePair list to 'Upload Properties'

    These properties are pieces of your process business data that can be used to classify a document. You can initialize them by JS:
    ---
    tw.local.documentFilter = [];
    tw.local.documentFilter[0] = {name: 'instanceId', value: tw.local.instanceId};
    tw.local.documentFilter[1] = {name: 'businessData1', value: tw.local.businessData1};
    tw.local.documentFilter[2] = {name: 'businessData2', value: tw.local.businessData2};
    --- 

    Alright, once done with this step, your documents are now ready to be searched by CMIS query.
    Encapsulate the implementation of 'Delete Documents' in a Service Flow. The idea is that you are going to search for documents by the properties and then delete them using 'Delete' operation from Content Integration service.

    In 'Init Data' script, you prepare the properties that identify documents to be deleted. These should be declared as inputs to this service flow.
    ---
    // Prepare properties
    tw.local.properties = [];

    tw.local.properties [0] = {name: 'instanceId', value: tw.local.instanceId}; // This is instanceId i'm looking for
    tw.local.properties [1] = {name: 'businessData1', value: tw.local.businessData1};  // This is identifying prop 1
    tw.local.properties [2] = {name: 'businessData2', value: tw.local.businessData2};  // This is identifying prop 2

    // Loop counter
    tw.local.counter = 0;  // Since we don't have a bulk delete operation, we are going to have to loop through the list
    ---

    'Get docs' service flow will take the properties list and return the document ids (ECMIDs). It is implemented like this:



    In Query script, you prepare the CMIS search query
    ---
    tw.local.query = "SELECT cmis:objectId, cmis:name FROM IBM_BPM_Document";
    var conditions = " WHERE "
    for(var i = 0; i < tw.local.properties.listLength; i++) {
    conditions += "ANY IBM_BPM_Document_Properties IN ('" + tw.local.properties[i].name + "," + tw.local.properties[i].value + "') AND ";
    }
    tw.local.query += conditions.substring(0, conditions.length - 5);
    ---

    Then you use Content Integration's Search service

    And map the CMIS query to it

    And then in 'Parse Result' you want to parse and get the ECMIDs
    ---
    /* Property metadata is captured by the ECMPropertyMetadata business object */
    var columnMetadata = tw.local.searchResult.propertyMetadata;

    var idColumnIndex = -1;

    /*
    * Check if a search result found. Find which column contains the ID column and
    * save its index so we can retrieve the right value from each row.
    */

    if (tw.local.searchResult.numItems > 0) {
    for (var i = 0; i < columnMetadata.length; i++) {
    if (columnMetadata[i].queryName == 'cmis:objectId') {
    idColumnIndex = i;
    break;
    }
    }

    tw.local.documentIds = new tw.object.listOf.ECMID();

    var resultSet = tw.local.searchResult.resultSet;
    for (var i = 0; i < resultSet.row.length; i++) {
    tw.local.documentIds[i] = resultSet.row[i].column[idColumnIndex];
    }
    } else {
    /* No search result */
    }

    ---
    This is the hardest part. Once done, you can just simply loop through ECMIDs list and use the 'Delete' operation


    That's it. Once this service is tested and works. Simply call it either by a nested service flow or by Ajax call from Coach View and don't forget to provide the required business data.

    Hope this helps.

    Regards,
    Thong Huynh



    ------------------------------
    Thong Huynh
    Sydney NSW
    ------------------------------



  • 5.  RE: Delete all files associate with process instance.

    Posted Fri March 05, 2021 09:30 AM
    Thanks for help. I have been looking for a long time for a solution to the same problem :)
    Best Wishes
    Tom

    ------------------------------
    Tom Maliniak
    ------------------------------