Hello,
I'm trying to create a custom workflow activity to get the contact entity reference from the email.
The goal is to use this functionnality when I create a email in order to get the link on the contact from the email address.
And I have a problem : I can't select my output argument in the update form of the workflow :
Here is my code :
using System.Activities;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Messages;
using System;
using Microsoft.Xrm.Sdk.Client;
namespace ActivityLibrary3
{
public class CodeActivity1 : CodeActivity
{
[Input("To")]
public InArgument<string> to { get; set; }
 
[ReferenceTarget("contact")]
[Output("ContactId")]
public OutArgument<EntityReference> ContactId { get; set; }
// If your activity returns a value, derive from CodeActivity<TResult>
// and return the value from the Execute method.
protected override void Execute(CodeActivityContext executionContext)
{
// Obtain the runtime value of the Text input argument
IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();
//Create an Organization Service
IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
// Create query using querybyattribute
QueryByAttribute querybyexpression = new QueryByAttribute("contact");
querybyexpression.ColumnSet = new ColumnSet("contactid", "emailaddress1");
// Attribute to query
querybyexpression.Attributes.AddRange("emailaddress1");
string email = this.to.Get(executionContext);
// Value of queried attribute to return
querybyexpression.Values.AddRange(email);
// Query passed to the service proxy
EntityCollection retrieved = service.RetrieveMultiple(querybyexpression);
// Returned value
foreach (var c in retrieved.Entities)
{
this.ContactId.Set(executionContext, c.Attributes["contactid"]);
break;
}
//Guid contact_id = new Guid();
//foreach (Entity entity in retrieved.Entities)
//{
// contact_id = ((EntityReference)entity.Attributes["contactid"]).Id;
// break;
//}
//this.ContactId.Set(executionContext, contact_id);
}
}
}
I've tried different ways (one is in green at the end of the code) but now, I don't know why I can't select my output parameter.
Thank you for your help !!
David
*This post is locked for comments