Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamicActivity validation error in CRM 2011 workflow
    primarykey
    data
    text
    <p>I was building a workflow for a custom lead qualifying. I build a workflow in CRM and I am invoking the custom workflow activity passing the lead reference as an input parameter and I expect the reference of the created account as a return parameter.</p> <p>The code is:</p> <pre class="lang-C# prettyprint-override"><code>using System; using Microsoft.Xrm.Sdk; using Microsoft.Xrm.Sdk.Workflow; using Microsoft.Xrm.Sdk.Query; using System.Activities; using Microsoft.Crm.Sdk.Messages; namespace Quicksale { /// &lt;summary&gt; /// Provide the functionality to qualify a lead /// &lt;/summary&gt; public class QualifyLead : CodeActivity { #region Parameters [Input("EntityReference leadIn")] [ReferenceTarget("lead")] public InOutArgument&lt;EntityReference&gt; LeadReference { get; set; } [Output("newAccount")] [ReferenceTarget("account")] [RequiredArgument] public OutArgument&lt;EntityReference&gt; accountRef { get; set; } #endregion Parameters public Guid existingAccount(Guid leadId, IOrganizationService service) { QueryExpression accQuery = new QueryExpression("account"); ColumnSet accColumnSet = new ColumnSet("accountid"); accQuery.ColumnSet = accColumnSet; accQuery.Criteria = new FilterExpression(); accQuery.Criteria.FilterOperator = LogicalOperator.Or; accQuery.Criteria.AddCondition("originatingleadid", ConditionOperator.Equal, leadId); accQuery.Criteria.AddCondition("custom_editableoriginatinglead", ConditionOperator.Equal, leadId); EntityCollection retrieved = service.RetrieveMultiple(accQuery); Guid retrievedAccount = Guid.Empty; // Iterate through returned collection. foreach (var c in retrieved.Entities) { retrievedAccount = new Guid(c.Attributes["accountid"].ToString()); return retrievedAccount; } return Guid.Empty; } public Guid existingContact(Guid leadId, IOrganizationService service) { QueryExpression contQuery = new QueryExpression("contact"); ColumnSet contColumnSet = new ColumnSet("contactid"); contQuery.ColumnSet = contColumnSet; contQuery.Criteria = new FilterExpression(); contQuery.Criteria.FilterOperator = LogicalOperator.Or; contQuery.Criteria.AddCondition("originatingleadid", ConditionOperator.Equal, leadId); contQuery.Criteria.AddCondition("custom_editableoriginatinglead", ConditionOperator.Equal, leadId); EntityCollection retrieved = service.RetrieveMultiple(contQuery); Guid retrievedContactId = Guid.Empty; // Iterate through returned collection. foreach (var c in retrieved.Entities) { retrievedContactId = new Guid(c.Attributes["contactid"].ToString()); return retrievedContactId; } return Guid.Empty; } /// &lt;summary&gt; /// Overridden Execute() function to provide functionality to the workflow. /// &lt;/summary&gt; /// &lt;param name="executionContext"&gt;Execution context of the Workflow&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; protected override void Execute(CodeActivityContext executionContext) { #region context //Create the context IWorkflowContext context = executionContext.GetExtension&lt;IWorkflowContext&gt;(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension&lt;IOrganizationServiceFactory&gt;(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); ITracingService tracingService = executionContext.GetExtension&lt;ITracingService&gt;(); #endregion context tracingService.Trace("Retrieving lead..."); Entity leadEntity = Helper.ActualEntity(LeadReference.Get(executionContext), service); tracingService.Trace("Lead retrieved."); tracingService.Trace("Qualifying lead..."); QualifyLeadRequest req = new QualifyLeadRequest(); Guid leadId = new Guid(leadEntity.Attributes["leadid"].ToString()); req.LeadId = new EntityReference("lead", leadId); //Set the lead to qualified status req.Status = new OptionSetValue(3); //choose what records to create from the lead tracingService.Trace("Checking if lead has already been qualified as an account..."); Guid accountId = existingAccount(leadId, service); tracingService.Trace("If lead has already been qualified as an account checked."); req.CreateAccount = accountId == Guid.Empty; tracingService.Trace("Checking if lead has already been qualified as a contact..."); req.CreateContact = existingContact(leadId,service)==Guid.Empty; tracingService.Trace("If lead has already been qualified as a contact checked."); req.CreateOpportunity = false; QualifyLeadResponse resp = (QualifyLeadResponse)service.Execute(req); tracingService.Trace("Lead qualified."); tracingService.Trace("Retrieving account id..."); if (accountId == Guid.Empty) { accountId = existingAccount(leadId, service); } tracingService.Trace("Account id retrieved."); tracingService.Trace("Setting output account reference..."); accountRef.Set(executionContext, new EntityReference("account", accountId)); tracingService.Trace("Output account reference set."); } } } </code></pre> <p>When I execute the workflow I get this error:</p> <pre><code>Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: The following errors were encountered while processing the workflow tree:&amp;#13;&amp;#10;&amp;#39; DynamicActivity&amp;#39;: The private implementation of activity &amp;#39;1: DynamicActivity&amp;#39; has the following validation error: Compiler error(s) encountered processing expression &amp;quot;DirectCast(CustomActivityStep13_1_converted, Microsoft.Xrm.Sdk.EntityReference)&amp;quot;.Invalid L-value expression.:Reference expressions cannot end with Conversion. The provided expression&amp;#39;s type must exactly match the type T of VisualBasicReference&amp;lt;T&amp;gt; or LambdaReference&amp;lt;T&amp;gt;.Detail: &lt;OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts"&gt; &lt;ErrorCode&gt;-2147220970&lt;/ErrorCode&gt; &lt;ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /&gt; &lt;Message&gt;The following errors were encountered while processing the workflow tree:&amp;amp;#13;&amp;amp;#10;&amp;amp;#39;DynamicActivity&amp;amp;#39;: The private implementation of activity &amp;amp;#39;1: DynamicActivity&amp;amp;#39; has the following validation error: Compiler error(s) encountered processing expression &amp;amp;quot;DirectCast(CustomActivityStep13_1_converted, Microsoft.Xrm.Sdk.EntityReference)&amp;amp;quot;.Invalid L-value expression.:Reference expressions cannot end with Conversion. The provided expression&amp;amp;#39;s type must exactly match the type T of VisualBasicReference&amp;amp;lt;T&amp;amp;gt; or LambdaReference&amp;amp;lt;T&amp;amp;gt;.&lt;/Message&gt; &lt;Timestamp&gt;2013-09-25T08:40:17.2376169Z&lt;/Timestamp&gt; &lt;InnerFault&gt; &lt;ErrorCode&gt;-2147220970&lt;/ErrorCode&gt; &lt;ErrorDetails xmlns:d3p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic" /&gt; &lt;Message&gt;Unhandled Exception: System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree: 'DynamicActivity': The private implementation of activity '1: DynamicActivity' has the following validation error: Compiler error(s) encountered processing expression "DirectCast(CustomActivityStep13_1_converted, Microsoft.Xrm.Sdk.EntityReference)".Invalid L-value expression.:Reference expressions cannot end with Conversion. The provided expression's type must exactly match the type T of VisualBasicReference&amp;lt;T&amp;gt; or LambdaReference&amp;lt;T&amp;gt;. at System.Activities.Hosting.WorkflowInstance.ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager) at System.Activities.WorkflowApplication.EnsureInitialized() at System.Activities.WorkflowApplication.Enqueue(InstanceOperation operation, Boolean push) at System.Activities.WorkflowApplication.WaitForTurn(InstanceOperation operation, TimeSpan timeout) at System.Activities.WorkflowApplication.InternalRun(TimeSpan timeout, Boolean isUserRun) at Microsoft.Crm.Workflow.SynchronousRuntime.ActivityHost.StartWorkflowExecution(Activity workflow, ICommonWorkflowContext context) at Microsoft.Crm.Workflow.SynchronousRuntime.ActivityHost.StartWorkflow(ICommonWorkflowContext context) &lt;/Message&gt; &lt;Timestamp&gt;2013-09-25T08:40:17.2376169Z&lt;/Timestamp&gt; &lt;InnerFault i:nil="true" /&gt; &lt;TraceText i:nil="true" /&gt; &lt;/InnerFault&gt; &lt;TraceText i:nil="true" /&gt; &lt;/OrganizationServiceFault&gt; </code></pre> <p>Any ideas about why this is happening? It seems quite regular code to me</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload