Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Can we change jcr:primaryType of the node after it is created

Avatar

Level 4

Hi,

I am having requirement to add a custom folder properties , but my folder are created dynamically as nt:folder from backend. 

Since folder schema only applies to sling:folder, wanted to check if we can change the folder primary type in JCR.

1 Accepted Solution

Avatar

Correct answer by
Level 4

Thanks @kautuk_sahni ,

I have found these suggestions useful, for my case, I used CURL commands to change it on author , 

However on publisher i was not able to do the same , so i have unpublished the node and change the folder type in author using CURL and publish it again fixes the issue.

 

Thank you.

Poovitha S

View solution in original post

7 Replies

Avatar

Community Advisor

Yes, you can change folder from code by giving same name to the folder, just change  jcr:primaryType="sling:Folder"

 

<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
    jcr:primaryType="sling:Folder"
    jcr:title="test folder project"
    sling:resourceType="sling:Folder"/>

in filter.xml, you can update

<filter root="/<foolder-destination>/testfolder" mode="update"/>

 earlier testfolder was "nt:folder" now updated to sling:Folder

HeenaMadan_0-1659019513203.png

Thanks

Avatar

Community Advisor

jcr:primaryType is a protected property and can not be changed or removed by the application using the API. Please refer this document for more details :

 

https://developer.adobe.com/experience-manager/reference-materials/spec/jcr/1.0/6.7.5_Special_Proper...

 

You can restructure the old folders with Sling:Folder as jcr:primaryType using some script and update existing BE logic to create the folder as sling:Folder.

Avatar

Level 2

Goto folder properties and change it to "orderable". this will change the the primaryType from nt:folder to sling:orderedFolder. you can uncheck this again to the make primaryType to sling:folder

Screenshot 2023-06-23 at 12.51.45.png

Avatar

Level 3

YES! it is posible and i have it working correctly.

It is the same code that is used by the POST servlet when you want to change the folder properties using the UI

Node folderNode = folderResource.adaptTo(Node.class);
folderNode.setPrimaryType("sling:OrderedFolder");
folderNode.getSession().save();

Avatar

Administrator

@PoovithaSelvaraj Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.



Kautuk Sahni

Avatar

Correct answer by
Level 4

Thanks @kautuk_sahni ,

I have found these suggestions useful, for my case, I used CURL commands to change it on author , 

However on publisher i was not able to do the same , so i have unpublished the node and change the folder type in author using CURL and publish it again fixes the issue.

 

Thank you.

Poovitha S