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

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
    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans