<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Add a category to a document with Javascript in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105232#M73586</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Found the solution: Replace space by '_x0020_'.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 Aug 2007 17:20:08 GMT</pubDate>
    <dc:creator>lock999</dc:creator>
    <dc:date>2007-08-23T17:20:08Z</dc:date>
    <item>
      <title>Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105223#M73577</link>
      <description>How do you add a category to a document with javascript?&amp;nbsp; I have done something like the following://Get category nodevar nodeRef = search.luceneSearch("…");//Get categories from filevar cats = file.properties["cm:categories"];//Add new categorycats.push(nodeRef);//Update file categoriesfile.propert</description>
      <pubDate>Thu, 05 Jul 2007 19:23:51 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105223#M73577</guid>
      <dc:creator>nparry</dc:creator>
      <dc:date>2007-07-05T19:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105224#M73578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In Alfresco 2.0 the various JavaScript API objects mostly did not return "real" JavaScript Array objects, instead they returned simple java List objects, which are accessable by index but do not support the Array functions such as push(). This has been fixed in 2.1 and all appropriate objects return real Array objects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For 2.0 you need to do something like this to copy the existing values to a new Array and add the new value:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;//Get category node&lt;BR /&gt;var nodeRef = search.luceneSearch("…");&lt;BR /&gt;&lt;BR /&gt;//Get categories from file&lt;BR /&gt;var cats = file.properties["cm:categories"];&lt;BR /&gt;&lt;BR /&gt;//Add new category&lt;BR /&gt;var newCats = new Array();&lt;BR /&gt;for (var i=0; i&amp;lt;cats.length; i++)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp; newCats[i] = cats[i];&lt;BR /&gt;}&lt;BR /&gt;newCats.push(nodeRef);&lt;BR /&gt;&lt;BR /&gt;//Update file categories&lt;BR /&gt;file.properties["cm:categories"] = newCats; &lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kevin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 12:27:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105224#M73578</guid>
      <dc:creator>kevinr</dc:creator>
      <dc:date>2007-07-06T12:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105225#M73579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, Kevin.&amp;nbsp; Works great.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Jul 2007 17:00:49 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105225#M73579</guid>
      <dc:creator>nparry</dc:creator>
      <dc:date>2007-07-06T17:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105226#M73580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is it just me, or does this solution not work?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to do much the same thing as nparry, again using alfresco 2.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I try to set the categories property using an array of nodeRefs to the categories I want, the result is an exception saying that alfresco can't convert between an ArrayList and a NodeRef (it would seem it's not expecting an array here).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I can assign single categories fine by just assigning the nodeRef of the category directly, but this overwrites any categories that have previously been set.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is it just the case that you can't append categories using javascript?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 11:18:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105226#M73580</guid>
      <dc:creator>wayne</dc:creator>
      <dc:date>2007-08-07T11:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105227#M73581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wayne,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I did pretty much exactly what Kevin showed, and it worked well.&amp;nbsp; It's sounds like you may be assigning the new category node ref into an array, but it's hard to say for sure.&amp;nbsp; Post your javascript and let's have a look at it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Nick P&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 12:26:04 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105227#M73581</guid>
      <dc:creator>nparry</dc:creator>
      <dc:date>2007-08-07T12:26:04Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105228#M73582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the quick response.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's the interesting part of the javascript:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;&lt;BR /&gt;var catNodeRef = search.luceneSearch("…");&lt;BR /&gt;&lt;BR /&gt;var cats = document.properties["cm:categories"];&lt;BR /&gt;&lt;BR /&gt;var newCats = new Array();&lt;BR /&gt;for (var i=0; i &amp;lt; cats.length; i++)&lt;BR /&gt;{&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newCats[i] = cats[i];&lt;BR /&gt;}&lt;BR /&gt;newCats.push(catNodeRef);&lt;BR /&gt;&lt;BR /&gt;document.properties["cm:categories"] = newCats;&lt;BR /&gt;document.save();&lt;BR /&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 12:57:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105228#M73582</guid>
      <dc:creator>wayne</dc:creator>
      <dc:date>2007-08-07T12:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105229#M73583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, I think I see the problem.&amp;nbsp; search.luceneSearch() returns an array of Nodes that represent all the search matches.&amp;nbsp; Even if the search only returns one node, it will still give it to you in array form.&amp;nbsp; Instead of &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;var catNodeRef = search.luceneSearch("…");&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;do like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="language-none line-numbers"&gt;&lt;CODE&gt;var catNodeRef = search.luceneSearch("…")[0];&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;-Nick P&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 13:07:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105229#M73583</guid>
      <dc:creator>nparry</dc:creator>
      <dc:date>2007-08-07T13:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105230#M73584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What an annoying thing for me to have missed!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Fantastic help there Nick - works like a charm now.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Many thanks indeed,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Aug 2007 14:05:55 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105230#M73584</guid>
      <dc:creator>wayne</dc:creator>
      <dc:date>2007-08-07T14:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105231#M73585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;When i try to assign a category that has a space within the category&amp;nbsp; name, it throws an error shown below. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example1: &lt;/SPAN&gt;&lt;STRONG&gt;This code throws an error. Please note the space in category name "Northern America"&lt;/STRONG&gt;&lt;SPAN&gt;. Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;search.luceneSearch("PATH:\"/cm:generalclassifiable//cm:Northern America\"")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example 2: &lt;/SPAN&gt;&lt;STRONG&gt;This code does not throw an error. Please note there are no spaces in the category name "Europe"&lt;/STRONG&gt;&lt;SPAN&gt;. Code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;search.luceneSearch("PATH:\"/cm:generalclassifiable//cm:Europe\"")[0]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Error:&lt;/STRONG&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to run Actions due to error: Failed to execute script 'workspace://SpacesStore/6f5b4e4a-502c-11dc-936f-f31ee0725da9': Failed to execute script 'workspace://SpacesStore/6f5b4e4a-502c-11dc-936f-f31ee0725da9': &lt;/SPAN&gt;&lt;STRONG&gt;Wrapped org.alfresco.service.cmr.repository.datatype.TypeConversionException: The property value is not compatible with the type defined for the property&lt;/STRONG&gt;&lt;SPAN&gt;: property: {&lt;/SPAN&gt;&lt;A href="http://www.alfresco.org/model/content/1.0}categories" rel="nofollow noopener noreferrer"&gt;http://www.alfresco.org/model/content/1.0}categories&lt;/A&gt;&lt;SPAN&gt; value: [workspace://SpacesStore/fe6f9bbd-41dc-11dc-8596-ef2a34b171a0, workspace://SpacesStore/0558b6b3-41dd-11dc-8596-ef2a34b171a0, workspace://SpacesStore/17bd92ff-41dd-11dc-8596-ef2a34b171a0, workspace://SpacesStore/054ccfcc-41dd-11dc-8596-ef2a34b171a0, org.mozilla.javascript.Undefined@5a9737] value type: class java.util.ArrayList (AlfrescoScript#18) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any clues? &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2007 15:55:43 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105231#M73585</guid>
      <dc:creator>lock999</dc:creator>
      <dc:date>2007-08-23T15:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Add a category to a document with Javascript</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105232#M73586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Found the solution: Replace space by '_x0020_'.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Aug 2007 17:20:08 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/add-a-category-to-a-document-with-javascript/m-p/105232#M73586</guid>
      <dc:creator>lock999</dc:creator>
      <dc:date>2007-08-23T17:20:08Z</dc:date>
    </item>
  </channel>
</rss>

