Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Custom Workflow Activity Error: Entity Reference cannot have Id and Key Attributes empty

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi CRM Experts,

I have written a Workflow activity with a couple of out arguments that are of type EntityReference

[Output("Approver")]
[Default(null)]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> Approver { get; set; }

[Output("Next Milestone")]
[Default(null)]
[ReferenceTarget("wen_milestonetype")]
public OutArgument<EntityReference> NextMilestone { get; set; }

I have set default values and the workflow throws out the error below, when I'm trying to update a date field in one of the related entities

Guid milestoneid = getNextMilestoneId(MilestoneType, ProjectID);
Entity milestone = new Entity(Constants.Milestone.EntityName);
milestone.Id = milestoneid;
milestone[Constants.Milestone.ActualDate] = DateTime.Now;
this.Context.SystemOrgService.Update(milestone);

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: An exception has occurred in the [Wendys.Crm.WorkflowPlugins.Budget.PopulateBudgetApprovalsOnMilestone] plugin.
An unhandled organization service fault occurred during execution of the workflow activity.
Entity Reference cannot have Id and Key Attributes empty.Detail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
<ActivityId>3ad07b18-36a4-418b-9cf9-dae0ed97c17e</ActivityId>
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:int">0</d2p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d2p1:key>SubErrorCode</d2p1:key>
<d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:int">-2146233088</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>An exception has occurred in the [Wendys.Crm.WorkflowPlugins.Budget.PopulateBudgetApprovalsOnMilestone] plugin.
An unhandled organization service fault occurred during execution of the workflow activity.
Entity Reference cannot have Id and Key Attributes empty.</Message>
<Timestamp>2018-07-03T00:38:07.6531954Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource>SdkClient</ExceptionSource>
<InnerFault>
<ActivityId>106d9572-7dea-4845-9795-27cb6957247e</ActivityId>
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d3p1:key>OperationStatus</d3p1:key>
<d3p1:value xmlns:d5p1="www.w3.org/.../XMLSchema" i:type="d5p1:int">0</d3p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d3p1:key>SubErrorCode</d3p1:key>
<d3p1:value xmlns:d5p1="www.w3.org/.../XMLSchema" i:type="d5p1:int">-2146233088</d3p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Entity Reference cannot have Id and Key Attributes empty.</Message>
<Timestamp>2018-07-03T00:38:07.6778127Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource>SdkClient</ExceptionSource>
<InnerFault>
<ActivityId>106d9572-7dea-4845-9795-27cb6957247e</ActivityId>
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d4p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d4p1:key>OperationStatus</d4p1:key>
<d4p1:value xmlns:d6p1="www.w3.org/.../XMLSchema" i:type="d6p1:int">0</d4p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d4p1:key>SubErrorCode</d4p1:key>
<d4p1:value xmlns:d6p1="www.w3.org/.../XMLSchema" i:type="d6p1:int">-2146233088</d4p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Entity Reference cannot have Id and Key Attributes empty.</Message>
<Timestamp>2018-07-03T00:38:07.6778127Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault>
<ActivityId>106d9572-7dea-4845-9795-27cb6957247e</ActivityId>
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d5p1="schemas.datacontract.org/.../System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d5p1:key>OperationStatus</d5p1:key>
<d5p1:value xmlns:d7p1="www.w3.org/.../XMLSchema" i:type="d7p1:int">0</d5p1:value>
</KeyValuePairOfstringanyType>
<KeyValuePairOfstringanyType>
<d5p1:key>SubErrorCode</d5p1:key>
<d5p1:value xmlns:d7p1="www.w3.org/.../XMLSchema" i:type="d7p1:int">-2146233088</d5p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Entity Reference cannot have Id and Key Attributes empty.</Message>
<Timestamp>2018-07-03T00:38:07.6778127Z</Timestamp>
<ExceptionRetriable>false</ExceptionRetriable>
<ExceptionSource i:nil="true" />
<InnerFault i:nil="true" />
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<OriginalException i:nil="true" />
<TraceText i:nil="true" />
</InnerFault>
<OriginalException>System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault] with ErrorCode: -2147220891
at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)

There are no null Guids when I retrieve the records and the out arguments are set with values and the field name (that I'm retrieving to update) matches with schema name. I searched for this error resolution online for quite sometime couldn't find anything other than "we have to default the out arguments to null" 

https://community.dynamics.com/crm/f/117/t/254349

https://community.dynamics.com/crm/f/117/t/253463

Any help or suggestion is appreciated.

Thanks,

Vinod

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Custom Workflow Activity Error: Entity Reference cannot have Id and Key Attributes empty

    Hi Vinod,

    Are you sure that the error is in that Update operation? I'm thinking to a couple o possible causes:

    1) milestoneid is empty (is it possible?)

    2) You are using a empty Entity Reference for one of the output arguments.

    What do you think about?

    Bye

    Vincenzo

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,307 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans