Glad it is working.  Two things:

   1. You don't need the var og line.  I was just illustrating how you can 
   get the graph to use the graph api instead of the document api.  Actually, 
   you don't need db either.
   2. You don't need to call doc.save().  In fact, you probably shouldn't.  
   Let OrientDB do that for you.

All you need in your example is:


doc.field("lastUpdatedAt", new Date().getTime());

and I agree: using Java hooks is probably best but the dynamic nature of 
using javascript has some benefits.

On Saturday, June 25, 2016 at 2:58:50 AM UTC-4, scott molinari wrote:
>
> Yes, I was running the "execute" in Studio, when I got the error and your 
> explanation makes perfect sense why it won't work, now that you mention it. 
> I should have realized that, while doing it.
>
> But, with your help, I've gotten my trigger working. It's a custom 
> function "setLastUpdatedAt" and is triggered on "afterUpdate" and looks 
> like this:
>
> var db = orient.getDatabase();
>
> var og = (db.getTransaction().isActive())
>     ?orient.getGraph()
>     :orient.getGraphNoTx();
>
> var now = new Date().getTime();
>
> doc.field("lastUpdatedAt", now);
>
> doc.save();
>  
> return;
>
> And it works like a charm. 
>
> Though, I would imagine Java hooks would perform better, and since this 
> activity will be done as a standard part of my app, I'll probably go with a 
> Java hook eventually. This get's me further though, so I can continue work. 
>
> Thanks so much for the help. 
>
> @ODB Team - would you consider this a good solution for creating an update 
> trigger, which updates a date/time field? If yes, would you like me to add 
> it to the docs under custom functions? I wish I understood more about 
> digging into custom functions and using ODB's engine to work with it, I'd 
> do more of a write-up in the docs. 
>
> I feel this feature could be a wicked webinar!!!! 
>
> Scott
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to