Nuxeo Server

How to Inherit Metadata from a Parent Document

Updated: March 18, 2024

There are cases where you want a document to inherit some metadata values from its parent. In general, the goal is to benefit from the creation context of a document to infer some metadata values. For example, you can set a project_id metadata on your document type and on the workspace (or any type of container). Then your document type can inherit the project id value from its parent workspace. This is also useful when most of your documents are captured via Nuxeo Drive. Since Drive doesn't allow the setting of metadata values, you can only infer them from parent containers.

In this how-to, we will implement an event handler that will listen to the creation of documents. If the created document matches some predefined criteria, the listener will execute a content automation chain. The chain will copy the Dublincore "source" metadata value from the workspace to the created document.

To maintain inheritance, you need to use the event "Document Updated" and select the children document you want to update. This approach would work with a few documents below your parent documents only. For a larger number of documents, you should consider a lower level approach.

Prerequisite

To complete this how-to, you need the elements below to be already configured in your Nuxeo Studio project.

Creating the Event Handler

To implement the metadata inheritance listener:

  1. Create a new Event Handler (see how to bind an automation chain to an event handler).
  2. Fill in the filtering information below:
    • Events: Document created
    • Current document has one of the types: DocumentationItem
  3. Create the corresponding automation chain (see below for the chain parameters).

Creating the Automation Chain

Create an automation chain with the following operations and parameters:

- Context.FetchDocument
- Context.PushDocument
- Document.GetParent:
    type: Workspace
- Context.SetVar:
    name: sourceValue
    value: "@{Document[\"dc:source\"]}"
- Context.PopDocument
- Document.SetProperty:
    xpath: "dc:source"
    save: "true"
    value: "@{sourceValue}"