cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any way to remove node property using JS API?

masterhard
Champ on-the-rise
Champ on-the-rise
Hello,

I am using Alfresco 3.4 and I need to delete node properties by JS web script. I did not found any mentions of removing properties in docs or in ScripNode sources.

Removing property from properties array and saving node does not remove properties (I looked to the code and saw that properties are actually merged).

Is there any way to remove node property using JS API?
1 ACCEPTED ANSWER

like this:

delete node.properties["yourprefix:yourproperty"];
node.save();


View answer in original post

5 REPLIES 5

openpj
Elite Collaborator
Elite Collaborator
The unique way to remove properties in Alfresco is declaring all these properties in an aspect and then use the addAspect and removeAspect methods to manage the properties as you wish.

Hope this helps.

dnallsopp
Champ in-the-making
Champ in-the-making
But in Java, you can call nodeService.removeProperty() - is there no equivalent in JavaScript?

What if you just want to remove one property value (something that is optional), not the entire aspect (which might include mandatory properties too)…?

Or would just setting the value to null do the trick?

like this:

delete node.properties["yourprefix:yourproperty"];
node.save();


Great!

douglascrp
World-Class Innovator
World-Class Innovator

I believe both answers are correct.

If you want to remove properties from nodes, I mean, from all the nodes of some custom type, you should be changing the content model, as Piergiorgio Lucidi answered, but if the problem you are trying to solve is to remove residual properties, that are properties not defined anywhere, then you should be using the answer from