<?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 Problem moving node (Error: Node has been pasted into its own tree.) in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33287#M14068</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've just written a script using the Javascript API so I can use it as a Rule to a Space. Whenever a document enters in a space, it basically checks document's name to get the parent directory it will be stored in (document's name contains parent's folder name), then creates future parent directory (if it doesn't exist), and finally moves the document into it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having troubles with this last step. Whenever I try to move the document into the recently created folder, I get the following error:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;Node has been pasted into its own tree.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This is my code so far, which I think is pretty much auto-descriptive:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;var fileName= document.properties.name;&lt;BR /&gt;var fields = fileName.split('.');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var parentName= fields[0];&lt;BR /&gt;var newNode=space.childByNamePath(parentName);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;if (newNode === null) { //create folder and move document into it&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; newNode=space.createFolder(parentName);&amp;nbsp; //works&lt;BR /&gt;&amp;nbsp; document.move(newNode); //I'm getting the error here&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;}else{ //folder already exists, just move document into it&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; document.move(newNode); //here too&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;If I comment the &amp;nbsp;&amp;nbsp; document.move(newNode);&amp;nbsp;&amp;nbsp; lines everything else works fine. Parent folder is successfully created but obviously the document keeps stored at the root of the current space, which is not what I need. Indeed I need to move it into the actual folder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I doing something wrong? Any help would be much appreciated. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Aug 2017 09:12:38 GMT</pubDate>
    <dc:creator>mperez</dc:creator>
    <dc:date>2017-08-04T09:12:38Z</dc:date>
    <item>
      <title>Problem moving node (Error: Node has been pasted into its own tree.)</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33287#M14068</link>
      <description>I've just written a script using the Javascript API so I can use it as a Rule to a Space. Whenever a document enters in a space, it basically checks document's name to get the parent directory it will be stored in (document's name contains parent's folder name), then creates future parent directory</description>
      <pubDate>Fri, 04 Aug 2017 09:12:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33287#M14068</guid>
      <dc:creator>mperez</dc:creator>
      <dc:date>2017-08-04T09:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem moving node (Error: Node has been pasted into its own tree.)</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33288#M14069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;UPDATE: I've realized that the line:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;document.move(newNode);&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;works well inside the &lt;STRONG&gt;if&lt;/STRONG&gt; scope&lt;STRONG&gt;. &lt;/STRONG&gt;The error is being reproduced inside &lt;STRONG&gt;else&lt;/STRONG&gt;. It's probably a typing issue but I'm pretty lost with it and I don't know what am I missing.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Aug 2017 11:18:24 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33288#M14069</guid>
      <dc:creator>mperez</dc:creator>
      <dc:date>2017-08-04T11:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Problem moving node (Error: Node has been pasted into its own tree.)</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33289#M14070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;UPDATE 2: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is pretty weird. Depending on where I make the call it works or not.&lt;/P&gt;&lt;P&gt;The following code works and moves the document to the recently created folder: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;var nodeNouProjecte = space.childByNamePath(nomProjecte);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (nodeNouProjecte === null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; nodeNouProjecte = space.createFolder(nomProjecte);&lt;BR /&gt;&amp;nbsp; document.move(nodeNouProjecte);&amp;nbsp; &lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;But the following doesn't:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;var nodeNouProjecte = space.childByNamePath(nomProjecte);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (nodeNouProjecte === null) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; nodeNouProjecte = space.createFolder(nomProjecte);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;document.move(nodeNouProjecte);&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Also if I make the call inside an else clause, it won't work either and the same error will be produced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any clue at all about what could be going on here?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Aug 2017 13:13:26 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33289#M14070</guid>
      <dc:creator>mperez</dc:creator>
      <dc:date>2017-08-04T13:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Problem moving node (Error: Node has been pasted into its own tree.)</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33290#M14071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;SOLUTION:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I posted the question in StackOverflow (sorry to say that) and after a few minutes a person came up with a really great solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In case you're facing the same issue all you've got to do is to execute the Rule in background (ensure "Run rule in background" is enabled). That will do the trick.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Aug 2017 14:14:46 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/problem-moving-node-error-node-has-been-pasted-into-its-own-tree/m-p/33290#M14071</guid>
      <dc:creator>mperez</dc:creator>
      <dc:date>2017-08-04T14:14:46Z</dc:date>
    </item>
  </channel>
</rss>

