So far in this series we have covered the business problem and machine learning setup that drives the score based on the email content. We have also discussed how this approach can be extended to calculate an aggregated happiness index based on various behaviour points from within Dynamics CRM. In this instalment, let us focus on deploying the ML (machine learning) module as web service, so that it can be consumed from within Dynamics CRM.
Deploying the ML module as a web service
Once you have tested your module and you are happy with results of the trained model, you can deploy it as a consumable web service by clicking on the Deploy Web Service button at the bottom of the ML Studio’s Experiment screen as shown below
After deployment, the web service is available in the Web Services section of the Azure ML Studio. You can click on the record and view its properties. In order to connect to this service you will need an API key which can be found in the properties as shown below
The setup of this web service for our scenario is as below
Score – 0 for unhappy email
4 for a happy email
Consuming the ML web service from within Dynamics CRM
Once the service has been deployed, it can be consumed from both Javascript and server side code (e.g. a plugin or a custom workflow activity). To keep it simple we will consume it from within the JavaScript
The following script on the email form can be used to call the service and get the score. Here we are sending the body in the tweet_text parameter and retrieving the results in JSON format.
sendRequest: function (text) {
var service =
AzureScript.getRequestObject();
var url = "https://ussouthcentral.services.azureml.net/workspaces/xxxxxxxxxxxxxxxxxxx/services/xxxxxxxxxxxxxxx/execute?api-version=2.0&details=true";
var jsonObject
=
{
"Inputs":
{
"input1":
{
"ColumnNames":
[
"sentiment_label",
"tweet_text"
],
"Values":
[
[
null,
text
]
]
}
},
"GlobalParameters": {}
};
var dataString =
JSON.stringify(jsonObject);
if (service != null)
{
service.open("POST", url,
false);
service.setRequestHeader("X-Requested-Width",
"XMLHttpRequest");
service.setRequestHeader("Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
service.setRequestHeader("Accept",
"application/json");
service.setRequestHeader("Content-Type", "application/json;
charset=utf-8");
service.setRequestHeader("Content-Length", dataString.length);
service.send(dataString);
//Recieve
result
var
requestResults = eval('(' + service.responseText + ')');
try {
resultSentiment =
requestResults.Results.output1.value.Values[0][1];
resultProb =
requestResults.Results.output1.value.Values[0][2];
return
resultSentiment;
//alert(resultSentiment + " " +
resultProb);
}
catch
(err)
{
console.log('Unable to interpret
result');
}
}
}
In the next part we will see how this score gets used within Dynamics CRM

Like
Report
*This post is locked for comments