locked
Can workflow send case note(attachment) via email? RRS feed

  • Question

  • Hi all,

    I'd like to send case note via email, if the note is an attachment. alos send the attachment as an email attachment.

    Is it possible? how?

    Thanks in advance

    Alan

    Wednesday, April 7, 2010 3:19 AM

Answers

  • try this

    try
                {
                    activityparty Fromparty = new activityparty();
                    Fromparty.partyid = new Lookup();
                    Fromparty.partyid.type = SystemUser.ENTITY_NAME;
                    Fromparty.partyid.Value = new Guid("");
    
                    activityparty ToParty = new activityparty();
                    ToParty.partyid = new Lookup();
                    ToParty.partyid.type = Account.ENTITY_NAME;
                    ToParty.partyid.Value = new Guid("");
    
                    email email1 = new email();
    
                    email1.to = new activityparty[] { ToParty };
                    email1.from = new activityparty[] { Fromparty };
                    email1.subject = "attachment";
                    email1.description = "attachment";
    
                    CrmBoolean direction = new CrmBoolean();
                    direction.Value = true;
                    email1.directioncode = direction;
                    email1.regardingobjectid = new Lookup(Account.ENTITY_NAME, new Guid(""));
                    Guid emailid = crmService.Create(email1);
    
    
                    // Retrieve the annotation records of case using retrivemultipple
    
                    // Create the query for search.
                    QueryExpression query = new QueryExpression();
                    query.EntityName = EntityName.annotation.ToString();
    
                    // Set the filter condition to query.
                    ConditionExpression condition = new ConditionExpression();
                    condition.AttributeName = "objectid";
                    condition.Values = new object[1] { new Guid("") };
                    condition.Operator = ConditionOperator.Equal;
    
                    FilterExpression filter = new FilterExpression();
                    filter.Conditions = new ConditionExpression[] { condition };
    
                    query.ColumnSet = new AllColumns();
                    query.Criteria = filter;
    
                    // Retrieve the salesliteratureitem records.
                    BusinessEntityCollection entities = crmService.RetrieveMultiple(query);
    
                    // Check for the retrieved salesliteratureitem count.
                    if (entities.BusinessEntities.Length != 0)
                    {
                        for (int i = 0; i < entities.BusinessEntities.Length; i++)
                        {
                            annotation annotationAttachment = (annotation)entities.BusinessEntities[i];
    
                            if (annotationAttachment.isdocument)
                            {
                                // Create the activitymimeattachment record for an e-mail attachment.
                                activitymimeattachment setupEmailAttachment = new activitymimeattachment();
                                setupEmailAttachment.subject = "Example Email Attachement";
                                setupEmailAttachment.filename = "ExampleEmailAttachment.txt";
                                setupEmailAttachment.body = annotationAttachment.documentbody; // retrived attachment documnet body
                                setupEmailAttachment.mimetype = "text/plain";
                                setupEmailAttachment.attachmentnumber = new CrmNumber();
                                setupEmailAttachment.attachmentnumber.Value = 1;
                                setupEmailAttachment.activityid = new Lookup();
                                setupEmailAttachment.activityid.type = EntityName.email.ToString();
                                setupEmailAttachment.activityid.Value = emailid;
                                Guid setupEmailAttachmentId = crmService.Create(setupEmailAttachment);
    
                                SendEmailRequest emailRequest = new SendEmailRequest();
                                emailRequest.EmailId = emailid;
                                emailRequest.TrackingToken = "";
                                emailRequest.IssueSend = true;
                                SendEmailResponse emailresp = (SendEmailResponse)crmService.Execute(emailRequest);
                            }
                            else
                            {
                                // attachment will be a TextNode 
                                //annotationAttachment.notetext
    
                                // Which can be appended to email discription.
                            }
                        }
                    }
                }
                catch (Exception ex)
                { }

    http://www.allaboutdynamics.com
    Wednesday, April 7, 2010 6:18 AM

All replies

  • Case notes and attachments are saved in "annotation" type entity records.
    You need to write a workflow assembly to send email containing notes and attachments.
    Check these links
    http://www.experts-exchange.com/Database/Software/CRM/Q_23155188.html
    http://msdn.microsoft.com/en-us/library/ms913863.aspx
    http://msdn.microsoft.com/en-us/library/dd548518.aspx
    • Edited by Shahid_Hameed Wednesday, April 7, 2010 5:02 AM code link
    Wednesday, April 7, 2010 4:42 AM
  • Thank you Shahid_Hameed.

    But I don't find any code relating to sending case note attachments as email attachment.

    Wednesday, April 7, 2010 5:17 AM
  • try this

    try
                {
                    activityparty Fromparty = new activityparty();
                    Fromparty.partyid = new Lookup();
                    Fromparty.partyid.type = SystemUser.ENTITY_NAME;
                    Fromparty.partyid.Value = new Guid("");
    
                    activityparty ToParty = new activityparty();
                    ToParty.partyid = new Lookup();
                    ToParty.partyid.type = Account.ENTITY_NAME;
                    ToParty.partyid.Value = new Guid("");
    
                    email email1 = new email();
    
                    email1.to = new activityparty[] { ToParty };
                    email1.from = new activityparty[] { Fromparty };
                    email1.subject = "attachment";
                    email1.description = "attachment";
    
                    CrmBoolean direction = new CrmBoolean();
                    direction.Value = true;
                    email1.directioncode = direction;
                    email1.regardingobjectid = new Lookup(Account.ENTITY_NAME, new Guid(""));
                    Guid emailid = crmService.Create(email1);
    
    
                    // Retrieve the annotation records of case using retrivemultipple
    
                    // Create the query for search.
                    QueryExpression query = new QueryExpression();
                    query.EntityName = EntityName.annotation.ToString();
    
                    // Set the filter condition to query.
                    ConditionExpression condition = new ConditionExpression();
                    condition.AttributeName = "objectid";
                    condition.Values = new object[1] { new Guid("") };
                    condition.Operator = ConditionOperator.Equal;
    
                    FilterExpression filter = new FilterExpression();
                    filter.Conditions = new ConditionExpression[] { condition };
    
                    query.ColumnSet = new AllColumns();
                    query.Criteria = filter;
    
                    // Retrieve the salesliteratureitem records.
                    BusinessEntityCollection entities = crmService.RetrieveMultiple(query);
    
                    // Check for the retrieved salesliteratureitem count.
                    if (entities.BusinessEntities.Length != 0)
                    {
                        for (int i = 0; i < entities.BusinessEntities.Length; i++)
                        {
                            annotation annotationAttachment = (annotation)entities.BusinessEntities[i];
    
                            if (annotationAttachment.isdocument)
                            {
                                // Create the activitymimeattachment record for an e-mail attachment.
                                activitymimeattachment setupEmailAttachment = new activitymimeattachment();
                                setupEmailAttachment.subject = "Example Email Attachement";
                                setupEmailAttachment.filename = "ExampleEmailAttachment.txt";
                                setupEmailAttachment.body = annotationAttachment.documentbody; // retrived attachment documnet body
                                setupEmailAttachment.mimetype = "text/plain";
                                setupEmailAttachment.attachmentnumber = new CrmNumber();
                                setupEmailAttachment.attachmentnumber.Value = 1;
                                setupEmailAttachment.activityid = new Lookup();
                                setupEmailAttachment.activityid.type = EntityName.email.ToString();
                                setupEmailAttachment.activityid.Value = emailid;
                                Guid setupEmailAttachmentId = crmService.Create(setupEmailAttachment);
    
                                SendEmailRequest emailRequest = new SendEmailRequest();
                                emailRequest.EmailId = emailid;
                                emailRequest.TrackingToken = "";
                                emailRequest.IssueSend = true;
                                SendEmailResponse emailresp = (SendEmailResponse)crmService.Execute(emailRequest);
                            }
                            else
                            {
                                // attachment will be a TextNode 
                                //annotationAttachment.notetext
    
                                // Which can be appended to email discription.
                            }
                        }
                    }
                }
                catch (Exception ex)
                { }

    http://www.allaboutdynamics.com
    Wednesday, April 7, 2010 6:18 AM