cancel
Showing results for 
Search instead for 
Did you mean: 

How to compute a metadata on a document according to a metadata of its children with automation ?

Christophe_
Champ on-the-rise
Champ on-the-rise

I have a metadata called "total" on a document. This document can have a variable number of children documents, all having a metadata called "amount".

How can I parameter an automation chain to calculate the "total" from the parent document which must be equal to the sum of the "amount" of its children documents ?

Thanks for your help !

4 REPLIES 4

Bing_Ren
Confirmed Champ
Confirmed Champ

It seems to me the best bet is to implement somekind of event handler, listening change event on child document. Then child document get its parent to recalculate the total.

Thanks for your reply

I can think of mainly three ways to do this, but none I know exactly how to implement, because I myself is very green in Nuxeo development and am trying to figure out how to do simple things.

sdenef_
Confirmed Champ
Confirmed Champ

not the solution, but it can helps :

I did a groovy script for Nuxeo Shell, similar to your needs Hope it can inspire you

import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.PathRef;

def ref = Context["ref"];
def docRoot = null;

if (ref == null || ref == "") { return "Context execution variable not set : ref"; }

try {   
  if (ref.startsWith("/")) {
    docRoot = Session.getDocument(new PathRef(ref));
  } else {
    docRoot = Session.getDocument(new IdRef(ref));
  }
} catch (Exception e) {
  return "Exception: ${e.getMessage()}.";
}

def docRootAndChildren = [];
docRootAndChildren = Session.query("SELECT * FROM Folder WHERE ecm:path STARTSWITH '${docRoot.getPath()}'");

def total = 0;
for (doc in docRootAndChildren) {
  total += Integer.parseInt(doc.getProperty("dublincore", "source"));
}

return  "total = ${total}";
Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.