Hi all,
I'm enough new on Dynamics CRM and I'm working on CRM 2016
I'm trying to do a custom workflow but I have a problem with the entity reference output, I execute the following code and I receive this exception: "Entity Reference cannot have id and key attributes empty".
using System;
using System.Activities;
using System.Collections.ObjectModel;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Crm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Workflow;
using System.Linq;
using TCRMPlugins.ProxyClasses;
namespace TCRMPlugins
{
public partial class CustomerSearch: BaseWorkflow
{
[Input("Email")]
public InArgument<String> Email { get; set; }
[Output("Individual")]
[ReferenceTarget("contact")]
public OutArgument<EntityReference> Individual { get; set; }
protected override void ExecuteInternal(LocalWorkflowContext context)
{
var email = this.Email.Get(context.CodeActivityContext);
if (email != null)
{
var individualQuery = context.CrmContext.CreateQuery("contact")
.ToList()
.Where(c => c.GetAttributeValue<string>("emailaddress1") == email)
.FirstOrDefault();
if (individualQuery != null)
{
var individualFound = new ProxyClasses.Individual(
context.OrganizationService.Retrieve(
ProxyClasses.Individual.GetLogicalName(),
individualQuery.Id,
new ColumnSet(true)
)
);
if(individualFound != null)
{
var individualReference = new EntityReference(ProxyClasses.Individual.GetLogicalName(), individualQuery.Id);
this.Individual.Set(context.CodeActivityContext, individualReference);
}
}






