Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

How to use triggers to block update?

Node Link

Hello, I'm using apoc to implement triggers on my database, and I can't seem to find a way to have a trigger that blocks an update.

For instance, I have 10+ triggers that execute in "phase: after" once a certain property X is updated, and I wanted to have one other different trigger in "phase: before" that once said property X is to be updated, verified if it was a valid update based on a certain condition, and if not, it would be aborted and all the other 10+ triggers would not be activated.

What I'm trying to do is something similar to what is depicted below:

CALL apoc.trigger.add('blockUpdate','UNWIND apoc.trigger.propertiesByKey({assignedNodeProperties},"_executed") as prop
	WITH prop.node as n
	MATCH (n)<-[:someRelation]-(x) 
	WHERE  x._included=true OR x._executed=0

Is this possible?


you can use call apoc.util.validate(<predicate>, <message>), see

View solution in original post


you can use call apoc.util.validate(<predicate>, <message>), see

Node Link

Hi @stefan.armbruster, and thanks for the quick reply.

I've tried to use that function but I can't seem to get it right. I have noticed that it requires 3 arguments, the third one being a vector of arguments, and as such, I've used an empty one. This is what I have:

CALL apoc.trigger.add('blockUpdate','UNWIND apoc.trigger.propertiesByKey($assignedNodeProperties,"_executed") as prop
	WITH prop.node as n
        CALL apoc.util.validate( EXISTS((n)<-[:CONDITION]-(x{_included:true, _executed:0})), "Error msg", [])',

But after this trigger is inserted into the database, I can't do anything else... Can't create nodes, delete or update them. This is the error message I get after trying to do any of these operations:


Am I missing something concerning the syntax of this function?

Thanks again for your time.

EDIT (FIXED): If you just run that trigger neo4j will accept it, but if you have something in a query other than the CALL function you need to return something, and there is no error message concerning that. Instead, neo4j just crashes every other action, which is a rather odd behavior. To fix it, I just returned something after the CALL (it doesn't matter what is going to be returned). Just leaving this here in case it helps someone.

Once more, thank you.