Can we change jcr:primaryType of the node after it is created | Community
Skip to main content
Level 3
July 28, 2022
Solved

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

  • July 28, 2022
  • 5 replies
  • 3267 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by PoovithaSelvaraj

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

5 replies

HeenaMadan
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
July 28, 2022

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

Thanks

Sachin_Arora_
Community Advisor
Community Advisor
July 29, 2022

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_Properties_jcr_primaryType_and_jcr_mixinTypes.html

 

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.

muhammeds946397
Level 2
June 23, 2023

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

fmateen
Level 2
March 21, 2024

Thanks @muhammeds946397 that works and is simple solution 

Level 2
January 17, 2024

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();
kautuk_sahni
Community Manager
Community Manager
January 18, 2024

@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
PoovithaSelvarajAuthorAccepted solution
Level 3
January 18, 2024

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