Hello community,
I am trying to check whether a contact reference on salesorder entity has its email address field filled or not.
After checking in the code, I went to salesorder entity tried to activate the record and then I got this exception:
Error in function ValidationUtil.activateSalesEntity.executeAction(): Unexpected exception from plug-in (Execute): Ewe.Xrm.Workflows.SalesEntityValidator.SalesEntityValidator: System.NullReferenceException: Object reference not set to an instance of an object.
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35: Unexpected exception from plug-in (Execute): Ewe.Xrm.Workflows.SalesEntityValidator.SalesEntityValidator: System.NullReferenceException: Object reference not set to an instance of an object.Detail:
<OrganizationServiceFault xmlns:i="">www.w3.org/.../XMLSchema-instance" xmlns="">schemas.microsoft.com/.../Contracts"> <ActivityId>4492f158-64a7-43ee-b308-75c3f0f7a097</ActivityId> <ErrorCode>-2147220956</ErrorCode> <ErrorDetails xmlns:d2p1="">schemas.datacontract.org/.../System.Collections.Generic" /> <Message>Unexpected exception from plug-in (Execute): Ewe.Xrm.Workflows.SalesEntityValidator.SalesEntityValidator: System.NullReferenceException: Object reference not set to an instance of an object.</Message> <Timestamp>2021-11-04T09:01:46.9827722Z</Timestamp> <ExceptionRetriable>false</ExceptionRetriable> <ExceptionSource>PluginExecution</ExceptionSource> <InnerFault i:nil="true" /> <OriginalException>System.NullReferenceException at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout) at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary`2 inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions) at System.Threading.Tasks.Task`1.InnerInvoke() at System.Threading.Tasks.Task.Execute() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, String customActivityTypeName, IExecutionContext requestContext, Dictionary`2 sandboxServices, Boolean useDrawbridgeEnabled, Boolean chaosFailAppDomain) at Microsoft.Crm.Sandbox.SandboxAppDomainHelper.Execute(IOrganizationServiceFactory organizationServiceFactory, String customActivityTypeName, IExecutionContext requestContext, Dictionary`2 sandboxServices, Boolean useDrawbridgeEnabled, Boolean chaosFailAppDomain) at Microsoft.Crm.Sandbox.SandboxWorker.ExecuteCustomWorkflowActivity(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, SandboxRequestCounter& workerCounter, Boolean returnTraceInfo)</OriginalException> <TraceText i:nil="true" /> </OrganizationServiceFault> Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[ ins, Object[ outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[ ins, Object[ outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Crm.Sandbox.ISandboxHost.ExecuteCustomWorkflowActivityAndReturnTraceInfo(SandboxCallInfo callInfo, SandboxCustomActivityExecutionContext requestContext, Guid pluginAssemblyId, Int32 sourceHash, String assemblyName, Guid pluginTypeId, String pluginTypeName, String assemblyContents, Boolean returnTraceInfo) at Microsoft.Crm.Sandbox.SandboxCustomActivity.Execute(SandboxClient client, SandboxCallTracker callTracker, IExecutionContext requestContext, String assemblyContents, Boolean returnTraceInfo) at Microsoft.Crm.Sandbox.SandboxCodeUnit.Execute(IExecutionContext context) |
||
My C# Function is as followed:
private void ValidateIfAnsprechpartnerEmailAddressIsFilled() { var salesOrder = LocalContext.BaseEntity.BaseEntity; var ansprechpartnerRef = salesOrder?.GetAttributeValue(SalesOrder.Properties.vis1_ansprechpartnerid); var ansprechpartnerMailAddress = LocalContext.Manager.Retrieve(ansprechpartnerRef, "emailaddress1"); if (string.IsNullOrWhiteSpace(ansprechpartnerMailAddress.GetAttributeValue("emailaddress1"))) { ValidationsFailures.Add("Für den gewählten Ansprechpartner fehlt eine E-Mail-Adresse."); } }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156