Hi All,
I'm in CRM online, 9.0. When I try to assign entity(opportunity) to some user, I got the exception bellow. I got the exception regardless if I use Update or AssignEntity Message (which is now deprecated). I'm quite sure there is no empty entity reference because I logged Id and logicalName of the EntityReference. Also if I run the code from my desktop application there is no error. There is no error if I assign entity manually to the same user through UI. The workflow is run under System Administrator authority. The user to who I assign is System Administrator.
This is the code:
QueryExpression query = new QueryExpression();
query.EntityName = "opportunity";
query.ColumnSet = new ColumnSet(new string[] {
"ownerid" //, "owningteam", "owninguser" I tried also fetching these two attributes and adding them to opportunity before the update
}
);
FilterExpression criteria = new FilterExpression(LogicalOperator.And);
//....some criteria modification
query.Criteria = criteria;
query.Orders.Add(new OrderExpression("createdon", OrderType.Descending));
query.TopCount = 1;
var ec = OrgService.RetrieveMultiple(query);
if (ec?.Entities?.Count != 1) return false;
try
{
Entity lastOpportunity = ec.Entities[0];
// I retrieve all fields of the opportunity because so it is made in Microsoft sample for assigning entity. But it doesn't work also if I create entity and add only OwnerId to the Entity(with or without owningteam and owninguser.
Entity e1 = OrgService.Retrieve("opportunity", opportunityId, new ColumnSet(true));
e1.Attributes["ownerid"] = new EntityReference(((EntityReference)(e1.Attributes["ownerid"])).LogicalName, ((EntityReference)(e1.Attributes["ownerid"])).Id);
// tried also this:
// e1.Attributes["ownerid"] = lastOpportunity.Attributes["ownerid"];
// and this
// e1.Attributes["ownerid"] = new EntityReference( ((EntityReference)(e1.Attributes["ownerid"])).LogicalName, ((EntityReference)(e1.Attributes["ownerid"])).Id);
OrgService.Update(e1);
return true;
}
catch(Exception ex)
{
Logger.Trace(ex);
}
Exception thrown by the Update is this:
Entity Reference cannot have Id and Key Attributes empty. at
Server stack trace:
at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
at Microsoft.Crm.Sandbox.SandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object sandboxTraceSettingsObj)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [1]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Crm.Sandbox.ISandboxOrganizationService.Execute(String operation, Byte[] serializedRequest, Object traceSettings)
at Microsoft.Crm.Sandbox.SandboxOrganizationServiceWrapper.ExecuteInternal(OrganizationRequest request)
at myFunction(myFunctionParameters
*This post is locked for comments
I have the same question (0)


Report
All responses (
Answers (