Activities Archives - Aric Levin's Digital Transformation Blog http://aric.isite.dev/tag/activities/ Microsoft Dynamics 365, Power Platform and Azure Thu, 12 May 2022 04:11:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 Email enhancements in 2020 Wave 2 Release Plan http://aric.isite.dev/dynamics/post/email-enhancements-2020wave2/ Fri, 21 Aug 2020 20:16:00 +0000 https://aric.isite.dev/index.php/2020/08/21/email-enhancements-in-2020-wave-2-release-plan/ With the release of Microsoft Dynamics 365 and Power Platform 2020 Release Wave 2, Microsoft has made several enhancements related to the email experience in model-driven apps. This post will cover the email file attachment enhancements as well as the new experience for email templates.

The post Email enhancements in 2020 Wave 2 Release Plan appeared first on Aric Levin's Digital Transformation Blog.

]]>
With the release of Microsoft Dynamics 365 and Power Platform 2020 Release Wave 2, Microsoft has made several enhancements related to the email experience in model-driven apps. This post will cover the email file attachment enhancements as well as the new experience for email templates.

In previous months, Microsoft updated the email designer and included some additional features some as allowing us to include images, not only by using a Url, but also by uploading a file or using drag and drop functionality and dropping an image file into the editor directly.

Email Attachments

Now with the Release Wave 2 plan, attachments have received a minor uplift. This is probably the first of many, but it is a starting point. After you add a new attachment, you now have the option to Preview, Download or Delete the attachment by using the More Actions Menu in the Attachment subgrid.

Email Enhancements - Attachments

If you click on the Preview in the More Items menu, a modal window will open displaying the image or pdf of the file that you uploaded to be included in the email message (as shown in the image below). This works for image file types and portable document format (pdf), but not for Office documents at this point in time. The Preview option does not appear in the More Items menu for document types where preview is not supported.

Email Enhancements - Attachments Preview

Email Templates

If you navigate to Power Apps Admin Center (https://aka.ms/ppac), and go to Settings -> Templates and select Email Templates, that link will still redirect you (at the time of writing this article) to the classic interface where you can modify the email templates. If you go to your maker portal and open the Customer Service Hub, you will notice that in the Service area under the Templates group, there is an Email Templates subarea.

If you open a new or existing email template, you will notice that the same designer that is available for the email message, is also available here, hence a new design experience for email templates. You can add attachments to the email template as before and also insert dynamic text using the new designer.

Email Enhancements - Email Templates

On the command bar, you will see a button for Insert dynamic text. Clicking on the button will open a panel on the right hand side, which will enable you to select the entity, the field and the custom text for the field that you want to embed in your email template (as shown below). Dynamic text fields show up in the email message in light blue (as shown in the previous image)

Email Enhancements - Email Templates Dynamic Text

The New Email form also has some additional capabilities. When you click on the Insert Template button, the system will ask you to select that template (once you have selected the recipients), however, if you click on the drop down next to the email template, you get the option to convert your current email message into an email template, directly from the New Email form.

I am hopeful that this enhancements to emails and email templates will provide an improved experience to Dynamics 365 users.

The post Email enhancements in 2020 Wave 2 Release Plan appeared first on Aric Levin's Digital Transformation Blog.

]]>
Create Email Message with Attachment from a Note http://aric.isite.dev/dynamics/post/create-email-message-with-attachments/ Mon, 25 Dec 2017 18:59:00 +0000 https://aric.isite.dev/index.php/2017/12/25/create-email-message-with-attachment-from-a-note/ create-email-message-with-attachments

The post Create Email Message with Attachment from a Note appeared first on Aric Levin's Digital Transformation Blog.

]]>
Recently I saw a request of how to create an email message with an attachment that exists from a Note, and how to do this via a Plugin. I remembered doing something like that in an old project, so I thought that I would share the logic behind this.

The first thing is to decide how this will be called. This logic can be called from an Action or Plugin, but the logic will reside in backend code. How to initiate the process is up to you. Once we initiate the process, the first thing to do is to retrieve the notes from the existing entity that contains the note documents. In order to retrieve the notes, we need to implement the following logic:

        private EntityCollection RetrieveAnnotations(string entityName, Guid entityId)
        {
            QueryExpression query = new QueryExpression(Annotation.EntityLogicalName)
            {
                ColumnSet = new ColumnSet(true),
                Criteria =
                {
                    Conditions =
                    {
                        new ConditionExpression("objectid", ConditionOperator.Equal, entityId),
                        new ConditionExpression("objecttypecode", ConditionOperator.Equal, entityId)
                    }
                }
            };

            EntityCollection results = service.RetrieveMultiple(query);
            return results;
        }

 This logic will retrieve all of the annotations related to a particular entity record. I did not add another condition for IsDocument, but you can add it if required. I will show that in the end. The next step is to create to more functions. The first function is to create an email message, and the second in to add the attachment to the email message that I created. Let’s take a look at each one of these functions separately.

The Create Email Message function receives 4 Parameters: From (Type Entity), To (Type Entity), Subject (Type String) and Email Body (Type String), and returns the Guid of the Email Message that was created. The source is shown below, and can be modified to fit your exact needs:

        private Guid CreateEmailMessage(Entity from, Entity to, string subject, string description)
        {
            Guid emailid = Guid.Empty;
            Entity email = new Entity("email");

            EntityCollection fromParty = new EntityCollection() { EntityName = "activityparty" };
            fromParty.Entities.Add(from);
            email.Attributes["from"] = fromParty;

            EntityCollection toParty = new EntityCollection() { EntityName = "activityparty" };
            toParty.Entities.Add(to);
            email.Attributes["to"] = toParty;

            email.Attributes["subject"] = subject;
            email.Attributes["description"] = description;

            try
            {
                emailid = service.Create(email);
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                string message = "An error occurred in the CreateEmailMessage function";
                throw new InvalidPluginExecutionException(message);
            }
            return emailid;
        }

Once we create the email message we can add the attachment to the message. The information for creating the attachment is retrieved from the notes, so there is no real changes required. We will see how everything fits together at the end.

        private Guid AddAttachmentsToEmail(Guid emailId, string fileName, string documentBody, string mimeType)
        {
            Entity attachment = new Entity("activitymimeattachment");
            attachment["subject"] = "Attachment to Email";
            attachment["filename"] = fileName;
            attachment["mimetype"] = mimeType;
            attachment["body"] = documentBody;

            attachment["objectid"] = new Entity("email", emailId);
            attachment["objecttypecode"] = "email";

            try
            {
                Guid attachmentId = service.Create(attachment);
                return attachmentId;
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                string message = "An error occurred in the AddAttachmentsToEmail function";
                throw new InvalidPluginExecutionException(message);
            }
        }

 Now that the Email message is created, and the attachment is added to the email message, we need to just Send the Email Message. The function only needs the email Id of the message, but can be modified as needed:

        private void SendEmail(Guid emailId)
        {
            SendEmailRequest request = new SendEmailRequest();
            request.EmailId = emailId;
            request.TrackingToken = "";
            request.IssueSend = true;

            try
            {
                SendEmailResponse response = (SendEmailResponse)service.Execute(request);
            }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                string message = "An error occurred in the SendEmail function.");
                throw new InvalidPluginExecutionException(message);
            }
        }

Finally, we can put everything together in the CreateEmailLogic function which will retrieve the notes by calling the RetrieveAnnotations function, loop through the collection of the notes, check if they are a document, create the email message, add attachments and send the email. This is the way the entry point function looks like:

        private void CreateEmailLogic(string customEntityName, Guid entityRecordId)
        {
            EntityCollection notes = RetrieveAnnotations(customEntityName, entityRecordId);
            if (notes.Entities.Count > 0)
            {
                foreach (Entity note in notes.Entities)
                {
                    bool isDocument = Convert.ToBoolean(note["isdocument"]);

                    if (isDocument)
                    {
                        // Should check these attributes exist in Note
                        string documentBody = note["documentbody"].ToString();
                        string mimeType = note["mimetype"].ToString();
                        string fileName = note["filename"].ToString();


                        // Need to get information to generate email message
                        Guid emailId = CreateEmailMessage(from, to, subject, emailMessage);
                        AddAttachmentsToEmail(emailId, fileName, documentBody, mimeType);
                        SendEmail(emailId);
                    }
                }
            }
        }

There are many possible variations to  the above logic and functions, but with the above you can accomodate the requirements that you need. 

The post Create Email Message with Attachment from a Note appeared first on Aric Levin's Digital Transformation Blog.

]]>
Changing Settings for Activity Party in Email Form http://aric.isite.dev/dynamics/post/changing_settings_for_activity_party_in_email_form/ Wed, 19 Dec 2012 17:32:00 +0000 https://aric.isite.dev/index.php/2012/12/19/changing-settings-for-activity-party-in-email-form/ We have all used the email form in CRM 2011, however many times we might want to customize the activity party fields (to, cc, bcc), so that we can restricted the email enabled entities.

The post Changing Settings for Activity Party in Email Form appeared first on Aric Levin's Digital Transformation Blog.

]]>
We have all used the email form in CRM 2011, however many times we might want to customize the activity party fields (to, cc, bcc), so that we can restricted the email enabled entities.
The image below displays the default entities that will be shown when we click on the activity party lookup button. Notice that custom email enabled entities will also be shown on this list.

In order to modify the entities, we will have to set the lookuptypes, lookuptypeicons and lookuptypename attributes of the activity party field as shown in the code below.
We can also set the defaulttype that will display when we open the lookup dialog window.

We have all used the email form in CRM 2011, however many times we might want to customize the activity party fields (to, cc, bcc), so that we can restricted the email enabled entities.
The image below displays the default entities that will be shown when we click on the activity party lookup button. Notice that custom email enabled entities will also be shown on this list.

In order to modify the entities, we will have to set the lookuptypes, lookuptypeicons and lookuptypename attributes of the activity party field as shown in the code below.
We can also set the defaulttype that will display when we open the lookup dialog window.

function modifyActivityParty()
{
    var to = document.getElementById("to");
    to.setAttribute("lookuptypes", "1,2,10000");
    to.setAttribute("lookuptypeicons", "/_imgs/ico_16_1.gif,/_imgs/ico_16_2.gif,/WebResources/ico_license16.gif");
    to.setAttribute("lookuptypenames", "account:1,contact:2,bgx_license:10000");
    to.setAttribute("defaulttype", "10000");
}

After the customizations have been published, only the required entities will be shown on the when the activity party lookup control is opened.
You will notice that the License custom entity is the default entity as set in the defaulttype attribute.

In order to select multiple results, you will have to set the lookupstyle attribute to “multi” as well.

Note that the above code might have to be modified for other supported browsers after applying CRM 2011 UR12.
This blog post is no longer supported in newer releases of Dynamics CRM and Dynamics 365. Access to the DOM is deprecated.

The post Changing Settings for Activity Party in Email Form appeared first on Aric Levin's Digital Transformation Blog.

]]>