Hi
I have a requirement to change the ownership of the record before it gets created. Need to set the owner as a team. I can't opt for post operation as I have workflow to create work orders which are triggered on the record creation and inherits same owner. I am trying with below code but , it is giving invalid argument exception.
I am fetching OwnerTeam details from another entity
targetEntity["ownerid"] = new EntityReference("team", OwnerTeam.Id);// this does not work
// tried below as well
EntityReference owner = new EntityReference();
owner.Id = ((EntityReference)(OwnerTeam)).Id;
owner.LogicalName = ((EntityReference)(Owner)).LogicalName;
targetEntity["ownerid"] = owner;
As its preopertaion , I ma not calling create method again. I am able to change any other field like Name in this except the Owner.

Kindly note : I can do this manually on the form, it working fine, hence do not think its security issue. The team selected is of type Owner