Search code examples
javascriptorientdb

How to create a new doc within a javascript function in OrientDB


I would like to create a new Document within a javascript function which is triggered when an doc is updated, and is triggered before update.

The new Document is based in the document that I am trying to update.

My function is something like that:

var formattedDate = getDateUTC();
print(formattedDate);
var db = orient.getDatabase();
var newDocument = new com.orientechnologies.orient.core.record.impl.ODocument("Item_Process");
newDocument = doc;
newDocument.field("final_date").value = formattedDate;
newDocument.save();
db.commit();

The object to update is updated, but a new document is not created. There is not any error.

Many thanks in advance


Solution

  • Substitude this line:

    newDocument.field("final_date").value = formattedDate;
    

    with this one:

    newDocument.field("final_date", formattedDate);
    

    Hope it helps

    Regards