cancel
Showing results for 
Search instead for 
Did you mean: 

How to Identify current space?

snig
Champ in-the-making
Champ in-the-making
Hi

Me being a pretty new user in Alfresco, am struggling to create a feature.
The requirement is quite simple… I want to create a script which will create a new item (new node) in the current space from where the script is being invoked.
I call this script from a FTL which is actually in the custom view of a new space.

This is the code of the script:


var content = args["content"];
var newNode = space.createNode("test.txt", "cm:content");
newNode.content = content;
result = newNode.content;

Unfortunately, it generates error in space keyword - "space is not defined". My requirement is just to refer the current space and create a new item in that. I create a new space in the companyhome and invoked this script from there and got this error.

Please Help.

Thanks.
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
The 'space' object is available depending on the context and model setup for the script execution - you say "I call this script from a FTL" - how are you doing this exactly?

Thanks,

Kevin

snig
Champ in-the-making
Champ in-the-making
I invoked the script from FTL by YUI AJAX call.
The space object returns proper node if used in the FTL itself.
But, if written in a script and the script is invoked from that FTL, the "space" object returns NULL.

kevinr
Star Contributor
Star Contributor
I think the problem is that the script you execute from the FTL has no context for the "current" space. You will need to construct the URL to the script with the "contextPath=…" argument specifying the context for it to use.

Thanks,

Kevin

snig
Champ in-the-making
Champ in-the-making
Thanks Kevin… yes, that may be the case.
I, however, have written some manual coding to find the current space thru lucene.

Thanks, the problem is now solved.

BTW, in case anyone is struck in some similar problem, do ping… happy to share the code.