cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript behaviour - some functions not available

stevegreenbaum
Champ in-the-making
Champ in-the-making
I created a simple behavior that invokes a javascript function that specializes the type of the incoming document, but I receive an error when it is executed.

I tried two different methods:

1.   Using Javascript API – document.specializeType(“mytype”);

                Log message received - Cannot find function specializeType.


2.   Execute OOTB action – “specialise-type”

                Log message received - Can't find method org.alfresco.repo.jscript.ScriptAction.execute(org.alfresco.repo.jscript.ChildAssociation). (alfresco/extension/scripts/onDocumentUpdate.js#15)

There are no other ERROR in the log from startup.  I tried a different Javascript command – example – isSubType and receive the same error message.  I tried it in v3.4 and 4.0b with the same result.

The onCreateNode policy fires for cm:content.  The script does get executed, but the commands mentioned above fail.

Why can’t I access these items in a script when executed by a behavior?

Thanks
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
Are you sure you have a document in your "document" variable? Maybe do a logger.log on that variable, or if you are in a web script, fire up the JavaScript debugger UI and inspect it. Maybe you have a handle to the association rather than the document the association points to.

Jeff

stevegreenbaum
Champ in-the-making
Champ in-the-making
Wow!  You nailed it.  I added document.getChild() and now the specialize function works. 

I can't find this documented anywhere, should a jira be created?  Shouldn't the behaviour return the reference to the node itself? 
I retrieve the document using:  var document = behaviour.args[0];

jpotts
World-Class Innovator
World-Class Innovator
I don't do much with JavaScript behaviors. I prefer Java for that. But I believe the objects that get handed to the JavaScript behavior differ depending on the policy you are implementing.

Glad that fixed your problem.

Jeff