cancel
Showing results for 
Search instead for 
Did you mean: 

cant delete/cancel workflow instance

heck
Champ in-the-making
Champ in-the-making
Hi there,
we are using alfresco community edition V.4.0b

I wanted to delete all workflow instances (assuming this will delete all tasks as well).
So i wrote a webscript:

var wfDefs = workflow.getAllDefinitions();
for (i in wfDefs) {
   var wfDef = wfDefs[i]
   logger.error("Def:" + wfDef.id);
   var wfInsts = wfDef.activeInstances;
   for (j in wfInsts) {
      wfInst = wfInsts[j];
      logger.error("   Inst:" + wfInst.id);
      wfInst.cancel();
   }
}

that doesnt seem to work:
Message:   00240112 Wrapped Exception (with status template): 00242923 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/hecktests/heckhello.get.js': 00242922 Failed to execute supplied script: 00242921 TypeError: Cannot find function fatal. (AlfrescoJS#2)
   
Exception:   org.mozilla.javascript.EcmaError - TypeError: Cannot find function fatal. (AlfrescoJS#2)
   
   org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3350)
   org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3340)


Then i tried the same with delete()

var wfDefs = workflow.getAllDefinitions();
for (i in wfDefs) {
   var wfDef = wfDefs[i]
   logger.error("Def:" + wfDef.id);
   var wfInsts = wfDef.activeInstances;
   for (j in wfInsts) {
      wfInst = wfInsts[j];
      logger.error("   Inst:" + wfInst.id);
      wfInst.delete();
   }
}


This doesnt work because delete is a reserved JavaScript keyword.

   00240114 Wrapped Exception (with status template): 00242928 Failed to execute script 'classpath*:alfresco/extension/templates/webscripts/hecktests/heckhello.get.js': missing name after . operator (file:/ext/opt/alfresco-4.0.b/tomcat/shared/classes/alfresco/extension/templates/webscripts/hecktests/heckhello.get.js#514)
   
Exception:   org.mozilla.javascript.EvaluatorException - missing name after . operator (file:/ext/opt/alfresco-4.0.b/tomcat/shared/classes/alfresco/extension/templates/webscripts/hecktests/heckhello.get.js#514)
   
   org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
   org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:96)


I think this can be considered basic functionality, so it has to work somehow… i hope.

Any help is highly appreciated.

Thanks
Matthias Heckmann
6 REPLIES 6

jpotts
World-Class Innovator
World-Class Innovator
Is it a requirement to use JavaScript to do this? If not, have you tried using the workflow console?

Jeff

lotharmärkle
Champ in-the-making
Champ in-the-making
I think Jeffs suggestion to use the wf console is "the right thing to do here TM".

However, regarding your question, beware that the javascript logger object only has the method logger.log("…").
There is no .debug or .fatal as it is in javas log4j loggers.

heck
Champ in-the-making
Champ in-the-making
Hi,
Thanks a lot for your replies.

Yes, i am familiar with the workflow console. But i really intended to do this programmatically… Smiley Sad

Regarding the log object:
i am always using e.g
logger.error("Resolving task:" + taskId);
with the expected result.
just FYI.

Thanks anyways.

heck
Champ in-the-making
Champ in-the-making
Update again:

As u know, using wfInst.delete() doesnt work becuase delete is a reserved word in javascript.
if i instead use wfInst.cancel(), i get

JavaException: org.alfresco.scripts.ScriptException: 012120470 Failed to execute supplied script: 012120469 TypeError: Cannot find function fatal. (AlfrescoJS#2)

using this code

function main() {
   var wfDefs = workflow.getAllDefinitions();
   for (i in wfDefs) {
      var wfDef = wfDefs[i]
      logger.error("Def:" + wfDef.id);
      var wfInsts = wfDef.activeInstances;
      for (j in wfInsts) {
         wfInst = wfInsts[j];
         logger.error("   Inst:" + wfInst.id);
         wfInst.cancel();
      }
   }
}

but if i comment out the cancel(), like this:




function main() {
   var wfDefs = workflow.getAllDefinitions();
   for (i in wfDefs) {
      var wfDef = wfDefs[i]
      logger.error("Def:" + wfDef.id);
      var wfInsts = wfDef.activeInstances;
      for (j in wfInsts) {
         wfInst = wfInsts[j];
         logger.error("   Inst:" + wfInst.id);
         //wfInst.cancel();
      }
   }
}

the code runs and does what it s expected to do.

So, i can confirm, it seems like the "cant find fatal" thing hassth. to do with the cancel() method.

This is just a confirmation of observations.

Thanks for any reply.

Best Regards
Matthias Heckmann

mitpatoliya
Star Collaborator
Star Collaborator
but after commenting that line. Are you able to delete the workflows?

jpotts
World-Class Innovator
World-Class Innovator
If what you are trying to do is work around the "delete is a reserved word" problem, try using this syntax instead:

wfInst['delete']();

Jeff