NodeRef syntax in JavaScript API

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2006 06:59 AM
Hi Alfresco,
I'm trying to add categories to a document but started with a locale as this seems less complex to start with. Problem is I need to assign a nodeRef to the property but how should this nodeRef look like? In the node browser a nodeRef looks like workspace://SpacesStore/666345ce-1d81-11db-b398-13c0b9d26600 but it isn't accepted in my JavaScript. What am I doing wrong?
I'm trying to add categories to a document but started with a locale as this seems less complex to start with. Problem is I need to assign a nodeRef to the property but how should this nodeRef look like? In the node browser a nodeRef looks like workspace://SpacesStore/666345ce-1d81-11db-b398-13c0b9d26600 but it isn't accepted in my JavaScript. What am I doing wrong?
var folder = companyhome;var copy = document.copy(folder);if (copy != null){ copy.name = "new_"; // Add the English category to the document var nodeRef = "workspace://SpacesStore/666345ce-1d81-11db-b398-13c0b9d26600"; document.properties["cm:locale"] = nodeRef; copy.save();}
Labels:
- Labels:
-
Archive
4 REPLIES 4

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2006 07:08 AM
The JavaScript API does not deal with NodeRef values - everything is wrapped in an OO style API, so it deals with scriptable Node objects. This means any 'd:noderef' property value should be assigned a Node object directly.
So you need to get hold the Node that represents your category - by query i expect or from an existing Node that has the category you need already assigned.
Thanks,
Kevin
So you need to get hold the Node that represents your category - by query i expect or from an existing Node that has the category you need already assigned.
var folder = companyhome;var copy = document.copy(folder);if (copy != null){ copy.name = "new_"; // Add the English category to the document var node = search.luceneSearch(……)[0]; document.properties["cm:locale"] = node; copy.save();}
Thanks,
Kevin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2006 10:56 AM
Thanks Kevin, it works like it should! I can add a locale with JavaScript now. One small extra question… how to realize this for collection aspects, the generalclassifiable for example?
How do I add this nodeRef without removing the other categories?
var nodeRef = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}category\" AND PATH:\"/cm:generalclassifiable//cm:MyCategory\"")[0];copy.properties["cm:generalclassifiable"] = nodeRef;
Doesn't work because the copy.properties excepts a collection element. Tried to remove the index ([0]) at the end of the nodRef and to add an index at the end of the copy.properties but this doesn't solve it.How do I add this nodeRef without removing the other categories?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2006 12:56 PM
The 1.4 JavaScript engine now correctly supports multi-value properties - so you will be able to do this:
So to set a multi-value property, you simply fill an array with the appropriate object type and assign that.
Thanks,
Kevin
var categories = new Array(1);var nodeRef = search.luceneSearch("TYPE:\"{http://www.alfresco.org/model/content/1.0}category\" AND PATH:\"/cm:generalclassifiable//cm:MyCategory\"")[0];categories[0] = nodeRef;// … add further categories here to the arraycopy.properties["cm:generalclassifiable"] = categories;
So to set a multi-value property, you simply fill an array with the appropriate object type and assign that.
Thanks,
Kevin

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2006 04:04 AM
Thanks Kevin, again something that I'll try out once we get to the 1.4 release.
