Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Need help fixing error: SandboxFault.ThrowIfGuidEmpty: entityId --may be a coding issue with my Custom Workflow Activity

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have created a Custom Workflow Activity that is supposed to take a user's name from a text field called "Prepared By", match it with a user in the User entity, and convert it to a lookup.  Next, I want the workflow to update the "Modified By" field.  I have created a Custom Workflow Activity to try to get this to work.  However, I keep receiving the following error: SandboxFault.ThrowIfGuidEmpty: entityId

Plugin Trace:

[KED365.Workflows: KED365.Workflows.ModifiedBy]

[ModifiedBy: KED365.Workflows.ModifiedBy]

Entered QualifyLeads.Execute(), Activity Instance Id: 1, Workflow Instance Id: c3305b17-fb6a-475d-ba79-6bff35afcc21

QualifyLeads.Execute(), Correlation Id: 00dd9aaf-3bf6-43ac-b5c5-b69705625c65, Initiating User: fedbe350-de19-e911-a992-000d3a18032d

Exception: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: SandboxFault.ThrowIfGuidEmpty: entityId (Fault Detail is equal to Exception details:

ErrorCode: 0x80040203

Message: SandboxFault.ThrowIfGuidEmpty: entityId

TimeStamp: 0001-01-01T00:00:00.0000000Z

--

).

Error Message:

Unhandled exception:
Exception type: Microsoft.Crm.CrmException
Message: SandboxFault.ThrowIfGuidEmpty: entityId

at Microsoft.Crm.Sandbox.SandboxCodeUnit.ProcessException(Exception originalException, IExecutionContext context, SandboxClient client, SandboxCallTracker callTracker, Boolean isSafeToRetry, DateTime performanceExecutionStartTime, SandboxTracker tracker, Guid parentExecutionId, CrmException& crmException, String& assemblyContents)

at Microsoft.Crm.Sandbox.SandboxCodeUnit.<>c__DisplayClass24_0.<Execute>b__0()

at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)

at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)

at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePlugin.Execute(IServiceProvider serviceProvider)

at Microsoft.Xrm.RemotePlugin.CrmProvider.RemotePluginContainer.Execute(IServiceProvider serviceProvider)

at Microsoft.Crm.Workflow.Services.ProxyCustomActivity.Execute(CodeActivityContext executionContext)

-- End stack trace --

My workflow is triggered when the "Prepared By" field is updated, then I add in the custom workflow step.

Any ideas on how I can fix this error?

I haven't been able to get the workflow to actually update the "Modified By" field yet, so its possible it is a coding issue.  Please see code below and let me know if there is anything I can do to update my code to fix this issue.  I am fairly new to coding, so its possible I'm missing something simple.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Threading.Tasks;
using System.Activities;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk.Query;

namespace KED365.Workflows
{


/// </summary>
public class ModifiedBy : WorkFlowActivityBase
{
private Guid contactid;

[Input("User Full Name")]
public InArgument<string> UserFullName { get; set; }


/// <summary>
/// Executes the WorkFlow.
/// </summary>
/// <param name="crmWorkflowContext">The <see cref="LocalWorkflowContext"/> which contains the
/// <param name="executionContext" > <see cref="CodeActivityContext"/>
/// </param>
/// <remarks>
/// For improved performance, Microsoft Dynamics 365 caches WorkFlow instances.
/// The WorkFlow's Execute method should be written to be stateless as the constructor
/// is not called for every invocation of the WorkFlow. Also, multiple system threads
/// could execute the WorkFlow at the same time. All per invocation state information
/// is stored in the context. This means that you should not use global variables in WorkFlows.
/// </remarks>
protected override void Execute(CodeActivityContext activityContext, IWorkflowContext workflowContext, IOrganizationService orgService, ITracingService tracingService)
{
//get entity record for which plugin was fired
Entity _target = (Entity)workflowContext.InputParameters["Target"];


//check if portaluser name is to be obtained from custom createby or from custom modifiedby
if (workflowContext.MessageName.ToUpper() == "CREATE")
{
contactid = _target.Attributes.Contains("new_createdby") ? _target.GetAttributeValue<EntityReference>("new_createdby").Id : Guid.Empty;
}
else
{
contactid = _target.Attributes.Contains("new_modifiedby") ? _target.GetAttributeValue<EntityReference>("new_modifiedby").Id : Guid.Empty;
}

//retrieve contact fullname from contactid
var _contact = orgService.Retrieve("contact", contactid, new ColumnSet("fullname"));

string fullname = _contact.GetAttributeValue<string>("fullname");
if (_contact != null)
{
if (_contact.Attributes.Contains("fullname"))
{
fullname = _contact.GetAttributeValue<string>("fullname");
}

//retrieve Systemuser that has same name as that of new_portalcreatedby/ //new_portalmodifiedby
var query = new QueryExpression("systemuser");
query.Criteria.AddCondition("fullname", ConditionOperator.Equal, fullname);
var _user = orgService.RetrieveMultiple(query).Entities.FirstOrDefault();

if (_user != null)
{

//check if we need to update createdby or modifiedby
if (workflowContext.MessageName.ToUpper() == "CREATE")
{
_target["createdby"] = _user.ToEntityReference();
}
else
{
_target["modifiedby"] = _user.ToEntityReference();
}

//assign new target to plugin executioncontext
workflowContext.InputParameters["Target"] = _target;
}
}
}
}
}

*This post is locked for comments

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,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans