cancel
Showing results for 
Search instead for 
Did you mean: 

JavaScript API & NodeRef troubles

simon
Champ in-the-making
Champ in-the-making
Hi Alfresco,

I'm trying to retrieve the categories attached to a document with JavaScript API in Alfresco Enterprise 1.3.1. I tried the example from the JavaScript WIKI with the "var locale = document.properties.locale.properties.name;" command. I added the locale aspect to the document but get this error:
* Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/df918dab-380d-11db-9652-a5e698739f92': TypeError: Cannot read property "properties" from null (AlfrescoScript#25)
Tried the same for the categories but it returns a NodeRef for every category and I can't add the ".properties.name" after a NodeRef element, it returns the null object.
One special feature is all properties of type NodeRef are automatically converted into another Node object.
What does this mean? I think it's what I tried with both the locale and the categories but I can't get it to work. Any ideas?
3 REPLIES 3

kevinr
Star Contributor
Star Contributor
I'm trying to retrieve the categories attached to a document with JavaScript API in Alfresco Enterprise 1.3.1. I tried the example from the JavaScript WIKI with the "var locale = document.properties.locale.properties.name;" command. I added the locale aspect to the document but get this error:
* Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/df918dab-380d-11db-9652-a5e698739f92': TypeError: Cannot read property "properties" from null (AlfrescoScript#25)

Locale and categories are two different things. You cannot get a value from the locale property until you have set it to something, so 'null' is correct.

Tried the same for the categories but it returns a NodeRef for every category and I can't add the ".properties.name" after a NodeRef element, it returns the null object.
One special feature is all properties of type NodeRef are automatically converted into another Node object.
What does this mean? I think it's what I tried with both the locale and the categories but I can't get it to work. Any ideas?

There was a bug in the JavaScript engine where we did not correctly convert multi-value properties (such as categories!) to objects as expected by the script, this is fixed in HEAD/1.4.

Thanks,

Kevin

simon
Champ in-the-making
Champ in-the-making
I know categories and locale are two different things, I only used the locale to test with but I tried again and indeed, this works. Thanks Kevin.

Problem is I need the categories in the JavaScript API. When is the 1.4 Enterprise release planned?

kevinr
Star Contributor
Star Contributor
Is it possible to get the categories with the 1.3 javascript engine - but tricky. Basically the NodeRef values you have can be used to perform a lucene query to get each node by hand. So for each NodeRef value retrieved from the categories property, you need to build a Lucene query along the lines of:

ID:noderef
Note that the NodeRef.toString() can be used, but you will need to escape the ':' and '/' characters to '\:' and '\/' (yes annoying but needed for the lucene query parsing).

So you query will look something like this:

ID:workspace\:\/\/SpacesStore\/e4f30acf-e98b-11da-821a-936824f635fe
You can then execute the lucene query using the 'search.luceneSearch()' javascript call. The results from each query will be an Array of size 1 (assuming it finds the category - it should!) which will contain a correctly populated script Node object (i.e. you can execute .name and .properties or similar on it). So you query for each category in turn and that will give you what you need for now.

Hope this helps,

Kevin