'Create a trigger but only works with after insert

I come here because I have a problem and I don't know how to solve it. I'm trying to create a trigger that works after insert and after update. The trigger works with after insert, but not work with after update. When I do a insert, the trigger works. But when I update the lines, the trigger doesn't work. I've already made several corrections to the code, but I can't understand why it doesn't work.

I cannot understand the error. Can you help me?

Thank you.

BEGIN
update documentsheaders
inner join  entity_stockdocument_extrafields on entity_stockdocument_extrafields.StockDocument_id=documentsheaders.id
set 
documentsheaders.entitykeyid=entity_stockdocument_extrafields.entity
where 
documentsheaders.DocumentKeyId='ES' and
documentsheaders.entitykeyid<>entity_stockdocument_extrafields.entity
update documentsheaders
inner join entities on entities.KeyId=documentsheaders.EntityKeyId
set 
documentsheaders.EntityDescription=entities.Name
where 
documentsheaders.DocumentKeyId='ES' and
documentsheaders.EntityKeyId=entities.KeyId;
END 


Solution 1:[1]

Ok. I can separating the triggers and create a trigger for after insert:

BEGIN
update documentsheaders
inner join  entity_stockdocument_extrafields on entity_stockdocument_extrafields.StockDocument_id=documentsheaders.id
set 
documentsheaders.entitykeyid=entity_stockdocument_extrafields.entity
where 
documentsheaders.DocumentKeyId='ES' and
documentsheaders.entitykeyid<>entity_stockdocument_extrafields.entity
update documentsheaders
inner join entities on entities.KeyId=documentsheaders.EntityKeyId
set 
documentsheaders.EntityDescription=entities.Name
where 
documentsheaders.DocumentKeyId='ES' and
documentsheaders.EntityKeyId=entities.KeyId;
END 

This script works, But if I copy this script another trigger for after update, it no longer works. I tried change to this:

begin
IF cliente_stockdocument_extrafields.cliente<>documentsheaders.entitykeyid then
update documentsheaders
inner join cliente_stockdocument_extrafields on cliente_stockdocument_extrafields.StockDocument_Guid=documentsheaders.Guid
set 
documentsheaders.entitykeyid=new.cliente
where 
documentsheaders.DocumentKeyId='EDS' and
cliente_stockdocument_extrafields.StockDocument_Guid=documentsheaders.Guid;
end if;
END

I did not succeed.

thank you!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 enniac