cancel
Showing results for 
Search instead for 
Did you mean: 

How to remove bpm_package items programmatically

francesco_lilli
Champ in-the-making
Champ in-the-making
Hi all,

after a task rejection I need to remove one (it's the only one) package item programmatically. After that, I will choose my new file and continue with my workflow. The problem is NOT with the new file I'm adding, but with the old one which is not removed correctly.

In the user task I tried:


   <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
         <activiti:string>
            logger.log("TRYING TO REMOVE OLD (REJECTED) PACKAGE ITEM…");
            execution.setVariable('bpm_package', null);
         </activiti:string>
      </activiti:field>
   </activiti:taskListener>
   <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
          <activiti:string>
               logger.log("TRYING TO SET NEW PACKAGE ITEM…");
               execution.setVariable('bpm_package', task.getVariable('bpm_package'));
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>


This does not work as it still tries to point to a node which does not exist anymore. So I tried:


   <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
         <activiti:string>
            logger.log("TRYING TO REMOVE OLD (REJECTED) PACKAGE ITEM…");
            execution.removeVariable('bpm_package');
         </activiti:string>
      </activiti:field>
   </activiti:taskListener>
   <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
          <activiti:string>
               logger.log("TRYING TO SET NEW PACKAGE ITEM…");
               execution.setVariable('bpm_package', task.getVariable('bpm_package'));
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>


More or less same issue. And:


   <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
         <activiti:string>
            logger.log("TRYING TO REMOVE OLD (REJECTED) PACKAGE ITEM…");
            var input_package = execution.getVariable('bpm_package');
            input_package.remove();
            execution.setVariable('bpm_package', input_package);
         </activiti:string>
      </activiti:field>
   </activiti:taskListener>
   <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
      <activiti:field name="script">
          <activiti:string>
               logger.log("TRYING TO SET NEW PACKAGE ITEM…");
               execution.setVariable('bpm_package', task.getVariable('bpm_package'));
            </activiti:string>
          </activiti:field>
        </activiti:taskListener>


Which still does not work. I have the impression I'm missing something out there. Any idea?

12 REPLIES 12

frederikherema1
Star Contributor
Star Contributor
Thanks for posting back the solution, wasn't aware that an additional "save" was needed.

francesco_lilli
Champ in-the-making
Champ in-the-making
Probably it's not, just wanted to make sure.
Thanks again!

shadow4110
Champ in-the-making
Champ in-the-making
hello  frederikheremans,
i am new to activiti. will u please tell me where to put this class file in alfresco?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.