cancel
Showing results for 
Search instead for 
Did you mean: 

help in scripting

wps07032
Champ in-the-making
Champ in-the-making
Hello,

I've put together a simple web script to kick off the predefined "review and approve" workflow but currently getting an error about the document object:

Here is the error:
Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/sample/myworkflow.get.js': Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/org/alfresco/sample/myworkflow.get.js': ReferenceError: "document" is not defined. (AlfrescoScript#5)

Here is the script:

var workflow = actions.create("start-workflow");
workflow.parameters.workflowName = "jbpm$wf:review & approve";
workflow.parameters["bpm:workflowDescription"] = "proxy_server.gif";
workflow.parameters["bpm:assignee"] = "administrator";
workflow.execute(document);


proxy_server.gif is a document that is already being uploaded to the system and currently resides on "Company Home" content.

Isn't document is one of the objects available by default in the root scripting scope? 

BTW, please advice if there are any other errors found in the script above. 

Much Thanks.
3 REPLIES 3

pmonks
Star Contributor
Star Contributor
The root objects available to a JS script vary, depending on the context in which that script is executed (custom action vs workflow vs web script etc. etc.).

As documented at http://wiki.alfresco.com/wiki/Web_Scripts#.22Execute.22_Script, the "document" root object is not available to web script JS scripts, which makes sense given that the web script engine has no way of knowing which file in the repository to populate that root object with (ie. it has no way of knowing that you wish it to operate on your proxy_server.gif file in preference to any of the other files that are in your repository).

Instead you'll have to pass a reference to that file to your web script as a parameter (as a node ref or a repository path, for example).  Many of the web scripts included in Alfresco show examples of how to do this.

Cheers,
Peter

wps07032
Champ in-the-making
Champ in-the-making
Hi Peter,

I'm very new to Alfreso, would you kindly post one example here or point me to the exact location of where the Alfresco examples are.

Much appreciate.

Thanks.

pmonks
Star Contributor
Star Contributor
There are a number of example Web Scripts at http://wiki.alfresco.com/wiki/Web_Scripts_Examples.  The source code for the Web Scripts bundled with the product is also available, either in the full Alfresco source code (see http://wiki.alfresco.com/wiki/Alfresco_SVN_Development_Environment for details on obtaining this) or by looking in:

${TOMCAT_HOME}/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts
in an Alfresco installation (although note that this second option only contains the source code for Javascript / Freemarker backed Web Scripts - Java backed Web Scripts are compiled into the Alfresco WAR).