cancel
Showing results for 
Search instead for 
Did you mean: 

Executing a script

slothrop
Champ in-the-making
Champ in-the-making
I would like to have users copy the contents of a space to another space  using Javascript in v. 2.1.  The only way I know how to do this currently is by the following sequence of events from the space details page:

Run Action > Select "Execute a Script" from a dropdown > Set Values and Add > Select the script from a dropdown.

I would prefer to simplify this process somehow.  Clicking on an icon or a link from the space Details page would be good.  How would I proceed to do this?
13 REPLIES 13

slothrop
Champ in-the-making
Champ in-the-making
If this can't be done, is it possible to have only a subset of the JavaScript files displayed in the dropdown in a particular space.  If I have many javascript files for use in different spaces, it might be confusing for users to have to select among them - even if they are given descriptive names.

paullewon
Champ in-the-making
Champ in-the-making
Hi,

You can add a hypothetical copyFiles.js script as a custom menu action to the space browse menu by placing code similar to this in your web-client-config-custom.xml file:

<config>
      <actions>
      <!– Launch Add Aspect Dialog –>
         <action id="copy_files">
            <label>Copy Files</label>
            <script>/Company Home/Data Dictionary/Scripts/copyFiles.js</script>
         </action>
      <!– Add action to Actions Menu for a space in the SpaceBrowse screen–>
         <action-group id="space_browse_menu">
            <action idref="copy_files" />
         </action-group>
      </actions>
   </config>
  
Paul

slothrop
Champ in-the-making
Champ in-the-making
Thanks Paul,
This could be really helpful.  But where is the reference to the space?  Should the action-group id have a path - like "/Company Home/Submissions/space_browse_menu"?

paullewon
Champ in-the-making
Champ in-the-making
Hi,

You can hard code the destination space as a path in your .js:

var put_here = companyhome.childByNamePath("Content Updating Project/Backup Folder");

Or am I misunderstanding you?

Paul

slothrop
Champ in-the-making
Champ in-the-making
Paul,
I see now that you were responding to my first post and not my second.

Sorry for the misunderstanding.

kevinr
Star Contributor
Star Contributor
It is possible to call scripts via URL:
http://wiki.alfresco.com/wiki/URL_Addressability#Script_Command_Processor

So you could construct the appropriate URLs to the scripts and add them as links to a custom version of the space details page JSP.

Thanks,

Kevin

slothrop
Champ in-the-making
Champ in-the-making
Paul,
The xml code you recommended works for adding the action to the space dropdown but the dropdown is only available from outside the space.  If I want to move content from the User Homes/User/Submissions space I have to be in the User Homes/User space to select the file from the dropdown.  When I do that both "parent" and "space" are undefined for some reason.

This is not the end of the world, though.  I can assume that the user will only want to submit content from his or her Submissions folder and hard code it in, i.e.

var sourceFolder = userhome.childByNamePath("Submissions");

When I do this everything executes as it should.  The contents are moved but the web client goes to an error page containg only something like this,
"org.mozilla.javascript.Undefined@e55d75." 

Nothing is sent to the log.  When executing from inside the space details page via the

"Run Action > Select "Execute a Script" from a dropdown > Set Values and Add > Select the script from a dropdown"

sequence described above.  It works fine but this is much less convenient than I would like.


Kevin,
I've looked at the space-detail.jsp file.  That is one gnarly beast.  I'm not sure I'm ready to dig in to it just yet.

kevinr
Star Contributor
Star Contributor
The resulting page you see is not an error - it is the script output. It is quite common to want to return to the previous page after the execution of a script action. An easy way to achieve this is to add the following at the end of your script:

var goBack = "<script>history.back();</script>";
goBack;

Kevin

patrik
Champ on-the-rise
Champ on-the-rise
Hi! I want to be able to execute a script on a file by pushing a new button for the file in the space browser.

<config>
      <actions>
      <!– Launch Add Aspect Dialog –>
         <action id="test">
            <label>Test</label>
            <script>/Company Home/Data Dictionary/Scripts/testscript.js</script>
         </action>
      <!– Add action to Actions Menu for a space in the SpaceBrowse screen–>
         <action-group id="document_browse">
            <action idref="test" />
         </action-group>
      </actions>
   </config>

What do i do to tell the script what it should use for its context? Something like?

<config>
      <actions>
      <!– Launch Add Aspect Dialog –>
         <action id="test">
            <label>Test</label>
            <script>/Company Home/Data Dictionary/Scripts/testscript.js</script>
<params>
            <param name="contextPath">#{actionContext.nodeRef}</param>
       </params>

         </action>
      <!– Add action to Actions Menu for a space in the SpaceBrowse screen–>
            <action-group id="document_browse">
            <action idref="test" />
         </action-group>
      </actions>
   </config>

But i want the link to be the same type as:
http://localhost:8080/alfresco/command/script/execute?scriptPath=/Company%20Home/Data%20Dictionary/S...

Ideas? Am i on the right track?