Why a namespace is required?
Assets metadata in AEM might be updated from multiple 3rd party systems. Namespaces help us identify the source of the metadata.
To persist custom metadata properties to the binary. Unless a namespace is attached to a property, the property will not be persisted to the binary.
Its common knowledge that any updates to metadata node of an asset trigger metadata write-back workflow which writes the metadata to the binary/renditions. For write-back to write a property to the binary the property should have a namespace attached. Else the properties without namespace are ignored.
This premise can be confirmed by doing a quick test.
- Add a property w/o namespace ex. “testProperty” on the metadata node of the asset from crx and give it some random value.
- Add a custom namespace(xyz) and add a property(xyz:testProperty) with custom namespace on the metadata node of the asset.
- Run the metadata writeback. Properties on the metadata node should be written to original rendition.
- Download the original rendition, rename it and upload it again to AEM.
- “testProperty” is not available, while the xyz:testProperty is available on the asset metadata node.
There are other consequences of not having namespaces for custom properties like Bulk upload (tools like url-asset-importer or csvimporter) won’t work for properties w/o namespaces.
Creating a custom namespace
- Open CRX explorer -> http://localhost:4502/crx/explorer/index.jsp > Node Type Administration > Namespaces > Add >
a. Enter a url for the namespace (ex. “http://my-namespace”)
b. Enter the Prefix (ex. “custom”).
Adding namespace to code
Add namespace in nodetypes.cnd (old way)
In AEMaaCS repo-init is recommended way of adding namespaces