- Toll Free: 1-866-SONOMA1
- Blog
- Newsletter
- Contact Us
Sonoma Partners
Adding Notes to a Workflow E-mail
Posted by Jim Steger on December 23, 2008 |In a recent post on the Microsoft Dynamics CRM Team blog, I discuss how you can easily overcome some of the native limitations of the CRM workflow Send E-mail action with some simple workflow assembly classes. Recently, I have been implementing the new eService Accelerator for our own corporate web site and came across a need for another CRM workflow e-mail utility...the ability to include all the notes of a record into the body of a workflow e-mail.
To accomplish this, I created a new activity class within my workflow utilities project and used the following code:
using System; using System.Workflow.ComponentModel; using System.Workflow.Activities; using System.Web.Services.Protocols; using Microsoft.Crm.Sdk; using Microsoft.Crm.SdkTypeProxy; using Microsoft.Crm.Sdk.Query; using Microsoft.Crm.Workflow; using System.Collections; using System.Text; namespace SonomaPartners.Crm.Workflow.Utilities { [CrmWorkflowActivity("Format Notes", "Utilities")] public partial class FormatNotes : SequenceActivity { protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService)); IWorkflowContext ctx = contextService.Context; ICrmService service = ctx.CreateCrmService(); this.FormattedNotes = BuildNotesString(service, ctx.PrimaryEntityId); return base.Execute(executionContext); } public static DependencyProperty FormattedNotesProperty = DependencyProperty.Register("FormattedNotes", typeof(string), typeof(FormatNotes)); [CrmOutput("Formatted Notes")] public string FormattedNotes { get { return (string)base.GetValue(FormattedNotesProperty); } set { base.SetValue(FormattedNotesProperty, value); } } private string BuildNotesString(ICrmService service, Guid id) { StringBuilder results = new StringBuilder(); results.Append("Notes:<br>"); BusinessEntityCollection notes = new BusinessEntityCollection(); notes = RetrieveNotesForId(service, id); foreach (annotation note in notes.BusinessEntities) { results.Append(string.Format("{0}<br>", note.subject)); results.Append(string.Format("{0}<br><br>", note.notetext)); } return results.ToString(); } private BusinessEntityCollection RetrieveNotesForId(ICrmService service, Guid id) { QueryByAttribute query = new QueryByAttribute(); query.EntityName = "annotation"; query.ColumnSet = new ColumnSet(new String[] { "subject", "notetext", "createdby", "createdon" }); query.Attributes = new String[] { "objectid" }; query.Values = new Object[] { id }; query.Orders = new ArrayList(); query.Orders.Add(new OrderExpression("createdon", OrderType.Descending)); try { RetrieveMultipleRequest request = new RetrieveMultipleRequest(); request.Query = query; RetrieveMultipleResponse returnedNotes = (RetrieveMultipleResponse)service.Execute(request); return returnedNotes.BusinessEntityCollection; } catch (SoapException ex) { throw new Exception(ex.Detail.InnerText); } } } }
Now, your e-mail includes any notes in the body of the message as shown here:
Feel free to download the Visual Studio 2008 workflow utilities assembly solution file.
Btw, I also wanted to thank Steve Kaplan and Jim Glass for allowing me to contribute on the Microsoft Dynamics CRM Team blog.
Comments
Post a Comment
Contact Us for a Quote, or Personalized Demonstrationof Microsoft Dynamics CRM for Your Business.
Contact Us
Previous Post
Back to Blog
Great stuff as usual Jim. Thanks for sharing!
Posted by: Steve Kaplan | Dec 29, 2008 1:54:12 AM
HAPPY NEW YEAR…
Very interesting article whom you post.
Here I can read about feature and product reviews into additional knowledge for me and I am very grateful to the author of this blog.
Posted by: Yuwono | Dec 31, 2008 6:57:20 AM
Hi,
I use CRM 4.0 as a part of our SaaS application. We have a requirement where the user may send feedback to their college administrator. For this, we first create the feedback entry in crm and then from CRM send email to college administrator.
Now the issue, I use case entity to track the feedback information and have created custom attribute to store the user email. I want to make use of this email present in the case while sending email. Also i wanted to send to multiple users through workflow.
Kindly guide me for the above scenario
-hari
Posted by: Hari krishnan | Jan 6, 2009 1:57:40 AM
We implemented this solution and it works perfectly. Thank you very much. The only thing I can see that would improve on it, is if it could somehow change the modifiedon date. As it stands now, when you add a note, the client does not get notified if the workflow is based on the CASE entity.
Posted by: Larry | Feb 10, 2009 2:05:47 PM
Hi,
This sounds good. Though I havent tried it but want to know, if one of my notes is having an attachment will that be included as an attachment in the email?
Thanks.
Kamaldeep
Posted by: Kamaldeep | Feb 12, 2009 3:35:49 AM
Hi Jim,
Great post by the way. We have implemeted the eService Accelerator also and are looking for a way to add regarding email body text to the notes of the case without the html or rich text tags. Is this possible? Could you possibly point me in the right direction to do this?
Many Thanks,
Rory
Posted by: Rory | Feb 16, 2009 4:21:06 AM
This will be great if I can get it to work. However I have no back ground with any of this. Where can I find step by step instructions to get this code into my crm. Thanks
Posted by: nathan | Mar 27, 2009 8:32:51 AM