Tuesday, 13 May 2014

Customworkflows

public class SendEmail : CodeActivity
    {
        public static DependencyProperty EmailLookupProperty = DependencyProperty.Register("EmailLookup", typeof(EntityReference), typeof(SendEmail));

        [Input("Email to send:")]
        [ReferenceTarget("email")]
        public InArgument<EntityReference> EmailLookup
        {
            get;
            set;
        }

        protected override void Execute(CodeActivityContext executionContext)
        {
            if (executionContext == null)
            {
                throw new InvalidPluginExecutionException("Context is Null");
            }

            IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();
            IWorkflowContext workflowContext = executionContext.GetExtension<IWorkflowContext>();
            IOrganizationService crmService = serviceFactory.CreateOrganizationService(workflowContext.UserId);

            // Create a SendEmail request.
            SendEmailRequest req = new SendEmailRequest();
            req.EmailId = EmailLookup.Get<EntityReference>(executionContext).Id;
            req.TrackingToken = string.Empty;
            req.IssueSend = true;

            // Send the email message.
            SendEmailResponse res = (SendEmailResponse)crmService.Execute(req);
        }
    }

No comments:

Post a Comment