cancel
Showing results for 
Search instead for 
Did you mean: 

Script running with Script Node UUID, not Document Node UUID

timothy_michael
Champ in-the-making
Champ in-the-making
I know I'm dominating these boards lately, but I'm still seeing some very bizarre behavior (which I'm sure is just a byproduct of not understanding the application framework fully).

Right now, I have a script action showing up in the document_browse and doc_details_actions action groups. The action is defined as follows:

   <config>
      <actions>
         <action id="myAction">
            <label>My Action</label>
            <image>/images/icons/submit.gif</image>
            <script>/Company Home/Data Dictionary/Scripts/myScript.js</script>
         </action>
      </actions>
   </config>

When I go to run the script on a document, I get the following error:

org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/94d58aac-e3c0-11db-8f3d-abe0b2708ac6': ReferenceError: "document" is not defined. (AlfrescoScript#21)

Looking up that node uuid, I'm surprised to see it's referring to the node for the javascript file rather than the document I ran the action on. I was under the impression from the Javascript wiki article that the document object would be automatically set to the node I ran the action on, without requiring additional parameters from me.

So are parameters required from me? Which parameters do I need to provide? I tried actionContext.id, but that's also the uuid for the script node. Any help is appreciated. Thanks.
1 REPLY 1

kevinr
Star Contributor
Star Contributor
When I go to run the script on a document, I get the following error:

org.alfresco.error.AlfrescoRuntimeException: Error during command servlet processing: Failed to execute script 'workspace://SpacesStore/94d58aac-e3c0-11db-8f3d-abe0b2708ac6': ReferenceError: "document" is not defined. (AlfrescoScript#21)

Looking up that node uuid, I'm surprised to see it's referring to the node for the javascript file rather than the document I ran the action on. I was under the impression from the Javascript wiki article that the document object would be automatically set to the node I ran the action on, without requiring additional parameters from me.

The UUID refered to above is the UUID of the script that had the error - it does not refer to any objects the script may be referencing.

Currently you do need to pass in the arguments you want for the script to have access to. It's easy enough:

   <config>
      <actions>
         <action id="myAction">
            <label>My Action</label>
            <image>/images/icons/submit.gif</image>
            <script>/Company Home/Data Dictionary/Scripts/myScript.js</script>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>
      </actions>
   </config>

You can then access the 'id' parameter through the 'args' object in the script - and lookup the node you want.

TBH I'm not entirely sure why I don't setup the current context for the script automatically as the object in the context of the action - probably because at generation time it doesn't explicitly know if the object is a document, space or something else… It's probably worth raising a JIRA item for if you find the arguments annoying… Smiley Happy

Thanks,

Kevin