You don't need to retrieve the entity first if you already have the Guid of the record.
I don't have a CRM 4.0 environment to test but:
1) If you want to assign a value to a property it is not necessary to check (and add) the property first, just write:
entity["field name"] = ...;
but I'm not sure if this works also for the primary id field
2) The identity isn't a Lookup
type but a Key
type, so if your entity is new_holder
the id field is new_holderid
:
entity["new_holderid"] = new Key(guid);
because I can't check if this syntax works, you can always write:
entity.Properties.Add(new KeyProperty("new_holderid", new Key(guid)));
3) If you want to assign an int
you need to use CrmNumber
:
entity["fieldname"] = new CrmNumber(5);
Full example:
DynamicEntity entity = new DynamicEntity("new_holder");
entity.Properties.Add(new KeyProperty("new_holderid", new Key(guid)));
entity["field name"] = new CrmNumber(5);
TargetUpdateDynamic update = new TargetUpdateDynamic();
update.Entity = entity;
UpdateRequest request = new UpdateRequest();
request.Target = update;
UpdateResponse response = (UpdateResponse)service.Execute(request);
As I wrote before I don't have a CRM 4.0 instance, but you can try the code and check which syntax works