Skip to main content

Use Azure Machine Learning for Spam Detection in Email to Case process in Dynamics 365


The following is a guest post from InfoStrat's Dmitri Riz which is also available on the InfoStrat Tech Blog.

Major software platforms like Microsoft Azure are rapidly developing toolkits that simplify access to AI or Machine Learning technologies, making them available to a wider group of developers. This article shows how the new AI Builder tool on Microsoft Azure PowerApps allows for a quick development of a text classifier model and easy integration of the trained model in Dynamics 365 data processing.

I'll use the Dynamics 365 Email to Case process as a use case. Several of our clients are using this process to generate vast amount of customer support cases from incoming emails. Many of spam emails clear regular email filters and end up as cases in Dynamics, forcing Customer Service Reps to manually tag them as spam and close them.

The resulting set of spam cases represents a perfect training set for a binary text classifier model where feature text is represented by the Description field of the case entity and (for this example) the Resolution field contains the tag.

NOTE: I've used the SMS Spam Collection Data Set from UCI machine learning repository to create and classify sample cases using ham and spam tags.



While this post shows how detect SPAM cases, same techniques can be used to build additional text and/or image classifier models to add more detailed data categorization, such as assigning case priority or routing cases to queues or providing automated case responses.
I will set up two components to illustrate this scenario: first I will build and train a text classification model, and then I will build a Flow that will react to the Create event of the Case and will use this model to classify each case as Spam or Ham.

Step 1: Build and Train Text Classification Model with PowerApps AI Builder

Under AI Builder, click on Model, Build a Model and choose 'Text Classification'.


Click on 'Select Text' and follow prompts to select Case entity and Description field as Text data and select Resolution field during Tag selection step. 

Select your language, confirm the data and tag fields are correct and click on Train button to train the model. 

This process may take a while for a large data set.




Wait till the model is trained and confirm the model precision.



The final step to confirm that your new text classifier works is to test it. Click on Quick test button to test it. Try to supply several text values to make sure that the model can resolve all possible tags with sufficiently high confidence score.


Now that we've built our classifier, it's time to move to the second step.

Step 2: Build a Flow to detect SPAM Cases using Text Classification Model

First, we need to create a new Solution. On PowerApps Solutions menu, click +New Solution, enter solution name and save new solution.


Click on +New button and select Flow to create a new Flow.

Select Dynamics 365 connector and 'When a record is created' trigger and select your organization and Case entity.


Click on Add Action button and select Predict action (I renamed it as Classify Case). This action will use our new model to classify the Description text of each newly created case.



Select your model in the dropdown and manually set the Request Payload field to a JSON fragment shown above, referencing Case Description field.

Click on 'Add an action' and select Parse JSON action. It will interpret Predict action's output. Refer to this Microsoft article for the JSON schema that this step requires.

At this point, we should pause and test our solution to see if both components work together. 

Click on Save button and then on Test button. The flow will wait till new Case is created. 

Now, create a new Case record in Dynamics 365 and populate the Description field with a value that should be classified as SPAM. 

After a few moments the Flow run will complete. If everything was set up correctly, you should see Predict step output containing JSON fragment with data show below, where type value should resolve to one of your tags, and the confidence score showing the reliability of the prediction: 

"response": "{\"predictionOutput\":{\"results\":[{\"type\":\"spam\",\"score\":0.9111173}]} 


The last remaining step is to take the prediction tag and apply it to the Case record. 

For this example, I will simply save the tag in Resolution field (see screenshot in the beginning of the post), but you could just as easily cancel the SPAM cases within the same process.

Click on Add action, select Dynamics 365 connection and Update a record action.

Select your Dynamics Environment; select Case entity. 

Select Case (primary key from the newly created case) in Record Identifier field. Scroll down in the list of fields till you see Resolution and map it to type field of Parse JSON action.



Popular posts from this blog

Power Apps Portal: The Successor to Microsoft Dynamics Portal

In case you have been reviewing Microsoft's new pricing for its Dynamics products which was released this month and have been unable to find Dynamics Portal, it has been rebranded as PowerApps Portal and shifted to the PowerApps side of the Microsoft product family.


Rebranding the portal product underscores the importance of app scenarios involving external users such as customers and suppliers.  It also provides a simpler interface than Dynamics 365 for occasional users.

The new portal pricing is based on the number of unique users who log into the portal each month (for authenticated users) and on the number of page views for anonymous users.  "A login provides an external authenticated user access to a single portal for up to 24 hours. Multiple logins during the 24-hour period count as 1 billable login. Internal users can be licensed either by the PowerApps per app or per users plans, or a qualifying Dynamics 365 subscription."

Pricing starts at $200/mo. for 100 dail…

ScreenMeet Remote Support Tool for Dynamics 365 Customer Service

I met Lou Guercia when he was president and CEO of Scribe Software, the leading CRM integration tool.  Scribe was acquired by TIBCO Software in 2018.  I recently reconnected with Lou and learned about ScreenMeet, the company he joined as chief operating officer.   The following is a description of the product provided by ScreenMeet:

ScreenMeet is a cloud-based remote support tool designed to integrate with Dynamics 365 Customer Service. By enabling customer service and IT support organizations to address critical technical issues directly from their CRM or ticketing platform, it streamlines the process and provides a fully browser-based support experience.

You can also use ScreenMeet with other CRM products or even on its own without a CRM.

Here is a short video demo of ScreenMeet with Dynamics integration:


ScreenMeet - Cloud-based Remote Support Integrated with Dynamics 365 Customer Support Once integrated with a Dynamics 365 CS organization, the ScreenMeet widget appears on Case pa…

Microsoft PowerApps and Microsoft Flow Licensing for Beginners

NOTE: Since this post was written, Microsoft has updated pricing.  For current pricing, see https://powerapps.microsoft.com/en-us/pricing

Next month marks two years since Microsoft announced the preview of its Flow workflow automation product.  Since then, PowerApps and Microsoft Flow have been gaining in popularity.

We at InfoStrat are receiving more questions from customers on how PowerApps and Flow are licensed by Microsoft.  This is a brief overview with links to authoritative Microsoft resources with all the details.

What are PowerApps and Flow? Microsoft PowerApps is a framework derived from Dynamics 365 (formerly Dynamics CRM) that allow you to build apps either with or without a form interface.  PowerApps works with Microsoft Flow.

Microsoft Flow is is a cloud software tool to build automated workflows that connect to many Microsoft and non-Microsoft systems and services.  For instance, you could write a workflow which would create a record in Dynamics 365 whenever a new file …