Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plugin Pre Operation Create - Update field error

My plugin fire on Pre Create operation on Entity X. When trying to update a field on the Entity X using the following code I am getting error:

trEntity = (Entity)context.InputParameters["Target"];
trGuid = (Guid)trEntity.Id;

tr = (Entity)service.Retrieve("EntityX", trGuid,
                    new ColumnSet(new string[] { "field_a", "field_b" }));


tr["field_a"] = null;
service.Update(tr);

The error I am getting is: Entity X with Id = 11505683-2292-b537-e311-143710e56fb7 Does Not Exist

like image 880
Nick Avatar asked Feb 11 '14 00:02

Nick


1 Answers

Since you are in Pre-Create, the entity doesn't exist yet in the database.

You don't need to explicitly call Update in a Pre event. You can just update the Target entity (trEntity in your case) and the changes you make will be saved with the Create operation. The Target entity is the actual entity that is about to be created, so feel free to update fields directly on the Target in the Pre event.

trEntity = (Entity)context.InputParameters["Target"];
trEntity["field_a"] = null;
like image 101
Josh Painter Avatar answered Oct 19 '22 16:10

Josh Painter