Answered by:
Removing Email from Queue in Workflow

Question
-
Hi All,
Is there any way I can reomove email from queue using CRM workflow?
what has heppened is that we have written workflow which picks up the email coming in queue and converts it in to case and puts the case in the same queue.
Now email and case both remains in the queue, is there any way i can remove this email from queue so that users can see only case and not the relevant emails?
Friday, July 3, 2009 9:40 AM
Answers
-
Hi All,
Just created simple workflow to achieve this functionality....here is code in case some one needs it..
[CrmWorkflowActivity("Remove the Email from the Queue")] public class RemoveEmailFromQueue : System.Workflow.Activities.SequenceActivity { //Email Id Property public static DependencyProperty activityIdProperty = DependencyProperty.Register("activityId", typeof(Lookup), typeof(RemoveEmailFromQueue)); [CrmInput("ActivityId")] [CrmReferenceTarget("email")] public Lookup activityId { get { return (Lookup)base.GetValue(activityIdProperty); } set { base.SetValue(activityIdProperty, value); } } //Queue Id Property public static DependencyProperty queueIdProperty = DependencyProperty.Register("queueId", typeof(Lookup), typeof(RemoveEmailFromQueue)); [CrmInput("queueId")] [CrmReferenceTarget("queue")] public Lookup queueId { get { return (Lookup)base.GetValue(queueIdProperty); } set { base.SetValue(queueIdProperty, value); } } //output Property public static DependencyProperty resultProperty = DependencyProperty.Register("result", typeof(string), typeof(RemoveEmailFromQueue)); [CrmOutput("result")] public string result { get { return (string)base.GetValue(resultProperty); } set { base.SetValue(resultProperty, value); } } /// <summary> /// Execute Method of Workflow /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { try { IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService)); IWorkflowContext context = contextService.Context; // Obtain IcrmService so we can call into CRM SDK to retrieve ICrmService crmService = context.CreateCrmService(); // this property will have the email address that needs to be matched. string strEmailGUID = activityId.Value.ToString(); //"305c2ecb-c26b-de11-9ba7-0003ff2b38e4"; // this property will have queue that needs to be matched string strQueueID = queueId.Value.ToString();// "D0B55822-436A-DE11-8911-0003FF2B38E4"; DetachFromQueueEmailRequest objEmail = new DetachFromQueueEmailRequest(); // Assign Email GUID objEmail.EmailId = new Guid(strEmailGUID.Trim()); // Assign Queue GUID objEmail.QueueId = new Guid(strQueueID.Trim()); //execute request to removed it from queue DetachFromQueueEmailResponse response= (DetachFromQueueEmailResponse)crmService.Execute(objEmail); this.result = "Success"; return ActivityExecutionStatus.Closed; } catch(Exception ex) { return ActivityExecutionStatus.Canceling; } } }
- Marked as answer by Mayank Pujara Friday, July 17, 2009 12:07 PM
Friday, July 17, 2009 12:07 PM
All replies
-
Hi,I do not believe you can do this using a simple workflow.You will need to write a custom workflow to achieve this. You can use the DetachFromQueueEmailRequest in code to detach email from the queue.Hassan.
Hassan Hussain | http://hassanhussain.wordpress.com/- Proposed as answer by Hassan Hussain Friday, July 3, 2009 9:49 AM
Friday, July 3, 2009 9:49 AM -
Hi All,
Just created simple workflow to achieve this functionality....here is code in case some one needs it..
[CrmWorkflowActivity("Remove the Email from the Queue")] public class RemoveEmailFromQueue : System.Workflow.Activities.SequenceActivity { //Email Id Property public static DependencyProperty activityIdProperty = DependencyProperty.Register("activityId", typeof(Lookup), typeof(RemoveEmailFromQueue)); [CrmInput("ActivityId")] [CrmReferenceTarget("email")] public Lookup activityId { get { return (Lookup)base.GetValue(activityIdProperty); } set { base.SetValue(activityIdProperty, value); } } //Queue Id Property public static DependencyProperty queueIdProperty = DependencyProperty.Register("queueId", typeof(Lookup), typeof(RemoveEmailFromQueue)); [CrmInput("queueId")] [CrmReferenceTarget("queue")] public Lookup queueId { get { return (Lookup)base.GetValue(queueIdProperty); } set { base.SetValue(queueIdProperty, value); } } //output Property public static DependencyProperty resultProperty = DependencyProperty.Register("result", typeof(string), typeof(RemoveEmailFromQueue)); [CrmOutput("result")] public string result { get { return (string)base.GetValue(resultProperty); } set { base.SetValue(resultProperty, value); } } /// <summary> /// Execute Method of Workflow /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected override System.Workflow.ComponentModel.ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { try { IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService)); IWorkflowContext context = contextService.Context; // Obtain IcrmService so we can call into CRM SDK to retrieve ICrmService crmService = context.CreateCrmService(); // this property will have the email address that needs to be matched. string strEmailGUID = activityId.Value.ToString(); //"305c2ecb-c26b-de11-9ba7-0003ff2b38e4"; // this property will have queue that needs to be matched string strQueueID = queueId.Value.ToString();// "D0B55822-436A-DE11-8911-0003FF2B38E4"; DetachFromQueueEmailRequest objEmail = new DetachFromQueueEmailRequest(); // Assign Email GUID objEmail.EmailId = new Guid(strEmailGUID.Trim()); // Assign Queue GUID objEmail.QueueId = new Guid(strQueueID.Trim()); //execute request to removed it from queue DetachFromQueueEmailResponse response= (DetachFromQueueEmailResponse)crmService.Execute(objEmail); this.result = "Success"; return ActivityExecutionStatus.Closed; } catch(Exception ex) { return ActivityExecutionStatus.Canceling; } } }
- Marked as answer by Mayank Pujara Friday, July 17, 2009 12:07 PM
Friday, July 17, 2009 12:07 PM -
-
Hello Mayan,
I am not a developer, has this custom activity been packaged so that I co0uld use the standard customization import?
Thank you
Mark Bath
Monday, August 20, 2012 10:31 PM -
Hi mark,
Yes, I have provided them below..
CRM 4.0 - http://mayankp.wordpress.com/2010/03/02/removing-email-from-crm-queue/
CRM 2011 - http://mayankp.wordpress.com/2011/10/08/crm-2011-removing-email-from-queue/
see if above links helps regarding the same,...
MayankP
My Blog
Follow Me on TwitterTuesday, August 21, 2012 9:44 AM -
The Download link on that page is no longer valid . Thanks for the help by the way!!Tuesday, August 21, 2012 8:14 PM