web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
Unanswered

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

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans