cancel
Showing results for 
Search instead for 
Did you mean: 

Cascade of INBOUND Rules are not working

sbroussi
Champ in-the-making
Champ in-the-making
Hi,

I want to cascade some INBOUND Rule:
- folder A (drop zone)
  rule R1: import all incoming ACP files in folder B

- folder B (incoming files)
  rule R2: set a custom property to "new document"

Steps:
1) Using FTP, I post one ACP file in folder A.
2) The rule 1 is well played, the ACP is imported
    in the folder B
3) problem starts here…: The rule R2 see new
    incoming files, but the Javascript crashes
    on the line "document.save()" (see below) with a:
java.lang.NullPointerException
   at org.alfresco.repo.jscript.Node.save(Node.java:785)
4) After this crash, the database is corrupted (mySql, innoDB seems to be here but the transaction is not rollbacked).

Note that using the Web Client, I can play this script on a document
(Run action / execute a script). There is no error.

The script looks like:
if (document != null)
{
   // add the "myAspect" aspect and set the "stampStatus" to: "ToBeStamped"
   if (document.hasAspect("corp:myAspect"))
   {
      document.properties["corp:stampStatus"] = "ToBeStamped";
   }
   else
   {
      var props = new Array(1);
      props["corp:stampStatus"] = "ToBeStamped";
      document.addAspect("corp:myAspect", props);
   }
   document.save();
}
2 REPLIES 2

kevinr
Star Contributor
Star Contributor
You can found a subtle bug in the scripting service Node class.

The issue is that if the script falls through to the 'else' case then the properties collection on the Node has not yet been initialised when it then calls document.save(). The reason it's working when you run the script by hand is that I would assume the document already has the aspect applied by then, so the 'if' case is executed instead which will work ok.

I've fixed the issue.

Thanks,

Kevin

kevinr
Star Contributor
Star Contributor
FYI to get round the problem for now, change you script thus:


if (document != null)
{
   // add the "myAspect" aspect and set the "stampStatus" to: "ToBeStamped"
   if (document.hasAspect("corp:myAspect"))
   {
      document.properties["corp:stampStatus"] = "ToBeStamped";
      document.save();
   }
   else
   {
      var props = new Array(1);
      props["corp:stampStatus"] = "ToBeStamped";
      document.addAspect("corp:myAspect", props);
   }
}
Moving the document.save() solves the problem as it is not required anyway after the addAspect() call.

Thanks,

Kevin