Home » Dynamics » Send Invite to Contacts automatically for Microsoft Portal in Dynamics 365

Send Invite to Contacts automatically for Microsoft Portal in Dynamics 365

Text Widget

This is a text widget. The Text Widget allows you to add text or HTML to your sidebar. You can use a text widget to display text, links, images, HTML, or a combination of these. Edit them in the Widget section of the Customizer.

Introduction:

After installing/configuring the Portal for Dynamics 365 online, the first question that comes to our mind is, how will we give the Portal access/login to contacts?

In this blog, we will discuss few questions related to Portal access.

Question #1

As a System Administrator/CRM User, how can we send an invitation to Dynamics CRM contacts in order to provide access to Microsoft Dynamics CRM/365 Portal?

We can send an invitation to Dynamics CRM contacts by following few simple steps.

1. First, open the Contact record to which you want to send an invitation.

2. Then, click on Create Invitation button to create Invitation record with Invitation Code.

3. Save the Invitation record.

4. Now, run the Send Invitation

An email with the invitation link will be sent to the Contact.

Refer the following link to know more about these steps, http://bit.ly/2wmVofK

Question #2

As a System Administrator/CRM User, how can we send an invitation automatically when a contact is created in Dynamics CRM in order to provide access to Microsoft Dynamics CRM/365 Portal?

We can achieve this using a combination of manual workflow and workflow assembly. We need to create one workflow which will trigger on the creation of a contact. And then we just need to execute the steps mentioned above through the workflow.

However, generating invitation code is a bit tricky. We have to pass the Invitation code (which is unique for invitations) along with the invitation link.

Below is the screenshot of the workflow and explanation for each step;

Send Invite to Contacts automatically for Microsoft Portal in Dynamics 3651. Create an Invitation Code:

We have to call the workflow assembly that returns an auto-generated Invitation code as an output parameter.

Code that generates the invitation code (This is the same logic of generating invitation code as in OOB Invitation process.)

/// <summary>
    /// This assembly will return a randomly generated invitation code
    /// </summary>
    public class CreateInvitationCode : CodeActivity
    {
        [Output("Invitation Code")]
        public OutArgument<string> InvitationCode { get; set; }

        /// <summary>
        /// Execute the process and generate the code
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext codeactivitycontext)
        {
            #region (*Services & Context*)

            //Create Tracing Service
            ITracingService tracingservice = codeactivitycontext.GetExtension<ITracingService>();

            //Create the Workflow Context
            IWorkflowContext workflowcontext = codeactivitycontext.GetExtension<IWorkflowContext>();

            //Service Factory
            IOrganizationServiceFactory organizationservicefactory = codeactivitycontext.GetExtension<IOrganizationServiceFactory>();

            //Create the Organization Service
            IOrganizationService organizationservice = organizationservicefactory.CreateOrganizationService(workflowcontext.UserId);

            //Organization Context
            OrganizationServiceContext context = new OrganizationServiceContext(organizationservice);

            #endregion
            try
            {
                //create the code
                string code = string.Empty;// GetCodePartition() + GetCodePartition() + GetCodePartition() + GetCodePartition() + GetCodePartition() + GetCodePartition() + GetCodePartition() + GetCodePartition();

                //Declare random class to randomly generate a number between 0and 1
                Random rnd = new Random();

                //call the GetCodePartition() 8 times to create the code
                for (int index = 0; index < 8; index++)
                {
                    code += GetCodePartition(rnd);
                }
                //check if code has value
                if (code != string.Empty && code != null)
                {
                    tracingservice.Trace("Code: " + code);
                    //set the value in output parameter
                    this.InvitationCode.Set(codeactivitycontext, code.Trim().ToLower());
                }
            }
            catch (InvalidPluginExecutionException ex)
            {
                throw new InvalidPluginExecutionException("Execute" + ex.Message);
            }
        }

        /// <summary>
        /// Generate code partitions
        /// </summary>
        /// <returns></returns>
        private string GetCodePartition(Random rnd)
        {
            try
            {
                #region(Original function used in JScript)

                //  return Math.floor((1 + Math.random()) * 0x10000)
                //.toString(16)
                //.substring(1);

                #endregion

                //Create an integer number and then convert it to hexadecimal string
                string codePart = Convert.ToInt32(Math.Floor((1 + rnd.NextDouble()) * 65536)).ToString("X").Substring(1);
                return codePart;
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException("getCodePartition" + ex.Message);
            }
        }
    }

2Create an Invitation Record:

This workflow step will CREATE an Invitation entity record. Set the output parameter returned by Step 1 in the Invitation code. Then set the other required fields; Sender, Name, Type, Invite Contact, Assign to Account, etc.

3Call child workflow that runs for Invitation entity:

This workflow will create and send an invitation link. Below is the screenshot of the child Workflow;

Send Invite to Contacts automatically for Microsoft Portal in Dynamics 365 1a) Create Email:

This step creates an email record where we need to add an invitation link in the email body. Append the invitation code that we generated and saved on the Invitation record, at the end of portal invitation URL.

Send Invite to Contacts automatically for Microsoft Portal in Dynamics 365b) Call ‘Portals: Send Invitation’ assembly:

Call Microsoft Portal’s ‘Send Invitation’ custom workflow assembly that sends the email created above to invitees.

c) Update status of invitation record to Invitation sent:

The next step is to update the Invitation Record to set status reason as Sent.

4. Stop workflow:

The final step is to stop the workflow.

Hope this helps!

Clone Dynamics CRM/365 Records

from Microsoft Dynamics 365(CRM) Tips and Tricks http://bit.ly/2v5jUlI
via IFTTT


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: