I just want a simple custom workflow activity to return the accounted (guid value) so I can pass it to another activity like an email. this is the code that I am using . it is pretty simple but is not working
I need to run it "ON DEMAND", so, I would expect it would get at least the accountId of my selected record
the activity is appearing on the workflow wizard but when I use it, my workflow fails.
am I doing something wrong?
[CrmWorkflowActivity("Return accountid")]
public partial class RetrieveContactIDActivity : Activity
{
public static DependencyProperty ResponseProperty = DependencyProperty.Register("Response", typeof(string), typeof(RetrieveContactIDActivity));
[CrmOutput("ResponseId")]
[CrmReferenceTarget("account")]
public string Response
{
get
{
return (string)base.GetValue(ResponseProperty);
}
set
{
base.SetValue(ResponseProperty, value);
}
}
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
{
// Get the context service.
IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));
IWorkflowContext context = contextService.Context;
ICrmService crmService = context.CreateCrmService(true);
try
{
if (context.InputParameters.Properties.Contains("Target") && context.InputParameters.Properties["Target"] is DynamicEntity)
{
DynamicEntity entity = context.InputParameters.Properties["Target"] as DynamicEntity;
if (entity.Properties.Contains("contactid"))
{
Response = ((Key)entity.Properties["contactid"]).Value.ToString();
}
if (entity.Properties.Contains("id"))
{
Response = ((Key)entity.Properties["contactid"]).Value.ToString();
}
}
}
catch (SoapException ex) {
//logger.LogError(ex.Detail.InnerText);
}
catch (Exception ex) {
//logger.LogError(ex.Message);
}
return base.Execute(executionContext);
}
}