As a consultant, architect or just a blogger, you have to do a lot of demos. Recently, with my look at Sales Insights, the amount of data I needed was increasing. I had used Flow in the past to automate data entry, and it worked well, so I thought I would create some data for my environment using Flow, but first sourcing the data in Mockaroo.
Mockaroo
Mockaroo is a free data generator service which allows you to establish the fields you want and create a dummy import file for Dynamics. Great for my needs.
For Sales Insights Lead prediction, I need Leads. So, First and last name, email, account name, topic, job title and email. Mockaroo has various types which you can use to flesh out the data. Fake company names, random first and last name etc. It does a great job of ensuring the chosen name / last name also links to the email address. Some things I needed were not present, such as the topic. It doesn’t really matter for my demo what data was in there, just needed something random, which the type grocery products gives me.
Choose the number of rows you need, select the format as CSV and Download. Open in Excel to view your random data goodness.
Importing data into Dynamics has never been easier. Select Import from CSV from the Import from Excel menu on a view for the entity you want to import against (assuming you have enabled Import Data in security) and choose your file. Mockaroo uses double quotes for its quotation mark and comma as a separator. Select Review Mapping.
Here, map the CSV fields to the Dynamics fields, particular attention to the Primary fields which you need to populate. Hit Finish Import and this will queue your import job. Once successful, you will have a new set of “random” data for your use.
Augmenting your data in Flow
For Predictive Leads, you need 30 qualified and unqualified leads. To go through the steps to qualify each of the 1000 leads that were just added would be a time-consuming exercise. Also, there are some fields that the Predictive Leads default model would like, such as Industry type, budget, annual revenue and number of employees. These fields need updating with a random value prior to (dis)qualification.
Industry type is an option set. The Common Data Service connector at the moment doesn’t give the user the ability to retrieve the values so you have to resort to a Custom Connector.
I have been through customer connectors before, for my Org Settings app amongst others. A custom connector allows connection to the wider Power Platform API, where you can do all manner of things, but most importantly for us retrieve a list of options for a field.
Connector Action Definition
I am not going to go through the basics of the connector creation, see my previous posts for that. What is specific to this project is the action to retrieve the option set. The URL for retrieving a list of option set values is below.
|
|
{url} is just the standard Power Platform log in url. {Entity} and {field} select which entity and field you want to return the values for. For example, to return the gender code options on Contact, you would use this url.
|
|
Transposing to the requirement for a custom connector, allowing for path parameters.
|
|
The {} are placeholders for path parameters. Use this link in the Import Sample and choose Get as the verb should result in the below action configuration.
By editing the Query variable, you can make it default to Options, make it required and make it internal so it hides the value from your Flow call.
This should be enough for you to start with your Flow.
Update Leads Flow
This flow is manually triggered. First thing is to get the options set values, which is a call to the custom connector. I want the Industry Types, so use the entity lead and the field industrycode.
Next, get all the leads you want to update. In my scenario, all the leads created after yesterday which is still active. This is anything I imported.
Loop through the Leads and decide on whether it is going to be qualified or not. I do this by using the rand() function, which gives me a random integer between the first and second parameters. So, rand(1,4) would give me either 1, 2 or 3. As I want to favour qualified leads, only 1 counts as a lost deal. This will provide me with roughly 2/3 qualified leads.
Disqualification of a Lead
This is straight forward update record, but with a few interesting parts.
Firstly, using rand() again populated budget, employee and annual revenue. Use different min and max values to populate the values accordingly.
The only other interesting part is entering the Industry Type.
The expression is below and broken down to the key parts.
|
|
Firstly get all the options return by my custom connector call.
|
|
Next, select one of the options by choosing a random number between 0 (o indexed array) and the number of options returned. If I have 10 options, the list will be returned with items in slots 0 - 9. So this effectively chooses which one I am going to use by random.
|
|
Finally, the Option is actually an object, the value I actually need to populated in the record is Value
|
|
I know, not exactly low code. There are other ways to do this, with Selects, etc., but this gives a one-line expression.
Finally in this lead update, set the status and status reason.
Qualifying a Lead
Qualification of a lead is a little trickier. Start with a lead update, which is the same as the one for disqualification except you don’t set the status/status reason.
Next, call the Perform an unbound action action. This is only available if you are within a solution and using the current environment connector.
Select an entity, Lead, an Action, QualiifyLead and Item Id, the record that has just been updated. I have selected Yes for all the create options, so it will create a Contact, Account and Opportunity as it processes.
At the bottom of the action, also update the status of the lead to 3, which is Qualified.
The problem with this action is that it causes an error, the return from this action is an object where it is expecting an object. I am sure someone more skilled in the way of Flow will be able to tell me the real way of fixing this, but for me, I just add a Compose action that does nothing and ensures this action gets called whether the Qualification fails or not.
The full flow is below. I manage to qualify or not 1000 leads in 27 minutes, admittedly it took a couple of hours to build the flow, but still, 2 1/2 hours for 1000 lead qualifications is pretty good!
Hopefully this has showed you some of the tools available to you via Flow to manipulate data.
Title Photo by Luca Abad Lopez on Unsplash