Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics 365 Custom Workflow - System.Activities.InvalidWorkflowException: Entity Id must be specified for Update

Posted on by Microsoft Employee

Hi Community,

I currently have a custom workflow in place that needs to grab the parent records ID and use it to fetch multiple records under another relationship, after which I need to update each of those child records with the ID of the entity record I am running the workflow from.

This is the error I am getting when running the workflow:

Entity-Id-must-be-specified-for-Update.jpg

What I cannot understand is that I've setup an exception and noted that there is a guid I'm getting from an input parameter:

Entity-Id-proof.jpg

When I choose to email a link, the only difference I can see if the uppercase GUID:

de80a8ec-e025-e911-a958-000d3a454977 - Exception
DE80A8EC-E025-E911-A958-000D3A454977 - Email a link

Here is the code I am currently using:

using System;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Crm.Sdk.Messages;

namespace NOSARequestSkillandRole
{
public sealed class Assessor : CodeActivity
{
[RequiredArgument]
[Input("This Events Assessment Request")]
[ReferenceTarget("ec_assessorrequest")]
public InArgument<EntityReference> AssessmentRequest { get; set; }

[RequiredArgument]
[Input("The Event")]
[ReferenceTarget("msevtmgt_event")]
public InArgument<EntityReference> Event { get; set; }

protected override void Execute(CodeActivityContext executionContext)
{
ITracingService tracer = executionContext.GetExtension<ITracingService>();
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

try
{
EntityReference EventEntity = this.Event.Get(executionContext);
Entity EventEntityRef = service.Retrieve(EventEntity.LogicalName, EventEntity.Id, new ColumnSet("msevtmgt_eventid"));

EntityReference AssessmentEntity = this.AssessmentRequest.Get(executionContext);

//Update Assessor Request into each Marksheet as a reference for the sub-grid
string fetch = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='ec_marksheet'>
<attribute name='ec_marksheetid' />
<attribute name='ec_name' />
<attribute name='createdon' />
<order attribute='ec_name' descending='false' />
<link-entity name='msevtmgt_eventregistration' from='msevtmgt_eventregistrationid' to='ec_eventregistration' link-type='inner' alias='ab'>
<filter type='and'>
<condition attribute='msevtmgt_eventid' operator='eq' uitype='msevtmgt_event' value='{0}' />
</filter>
</link-entity>
</entity>
</fetch>", EventEntityRef.Id.ToString());

EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetch));

foreach (Entity oMarksheetRecord in results.Entities)
{
Entity newMarksheet = new Entity("ec_marksheet");

newMarksheet["ec_assessorrequest"] = new EntityReference("ec_marksheet", AssessmentEntity.Id);

service.Update(newMarksheet);
}
}

catch (Exception e)
{
throw new InvalidWorkflowException(e.Message);
}
}
}
}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics 365 Custom Workflow - System.Activities.InvalidWorkflowException: Entity Id must be specified for Update

    Hi Kokulan,

    Thank you for the reply, I found the issue, it was because I was creating the entity "Entity newMarksheet = new Entity("ec_marksheet");" instead of updating the entity I was running the workflow against.

    Resolved.

  • Suggested answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Dynamics 365 Custom Workflow - System.Activities.InvalidWorkflowException: Entity Id must be specified for Update

    Could you share the full error details from the  Details/Comments area of the workflow. This area will have more details about the fail.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans