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