We’ve tried to remove a STRING property from an existing document using the method WorkflowDocumentManagerImpl.createOrUpdateDocumentFromVariantContentNode(). However, despite creating a new updated ContentNode instance without the desired property, it hasn’t resulted in the property’s removal from the document.
Efforts to specify a null value for the property have led to an exception. Moreover, leaving the property unspecified in the new ContentNode hasn’t achieved the removal of the property from the document.
How can we successfully remove a property from a node/document when updating it via WorkflowDocumentManagerImpl.createOrUpdateDocumentFromVariantContentNode()?
I assume this is with a Groovy script? Have you tried targeting the node(s) you want to remove from and using node.setProperty("propname", ((String)null)? I believe that removes the property from the node.
Since you won’t be using WorkflowDocumentManagerImpl.createOrUpdateDocumentFromVariantContentNode() then you need to remove the property from all the variants, and consider if you have any publishing workflows that wouldn’t be triggered.
We’re not using a Groovy script for this; instead, we’re working within Java. However, assigning a null value to a String property leads to an exception, unfortunately.
ContentNode.getProperty() returns a ContentProperty which doesn’t have a .remove() method. Instead, it does have a .removeValues() method which clears the list of values for that property.
However, assigning an empty list of values to a String property does not update (i.e. remove) that String property, unfortunately.
Thank you for your response. I’ve been digging deeper into this stuff and I’m starting to wrap my head around the underlying mechanisms. My aim is to make it easier to update or create a document by using a ContentNode, kind of like how EXIM does it.
Unfortunately, I’ve just found out that what I wanted to do isn’t doable. (Hippo JCR POJO Binding Documentation – Introduction (bloomreach-forge.github.io)) The method WorkflowDocumentVariantImportTask.createOrUpdateDocumentFromVariantContentNode() uses the DefaultJcrContentNodeBinder to link ContentNode and JCR nodes, but it can’t remove those main properties I wanted to get rid of.
I’m going to take a step back for now and figure out what my next move should be.
Again, thank you.
PS: in my original post I mistakenly mentioned WorkflowDocumentManagerImpl. I meant to say WorkflowDocumentVariantImportTask instead.