This way we can control the percentage of who gets what.
So we want salesperson1 to receive 30% of the calls and salesperson2 gets 70% of the calls. To do this with workflows we will need a field on new leads that populates with a random number. Then in the workflows we will say something like, when a new lead is created; if randomnumber field is equal to or less than 30 then assign to salesperson1 else assign to salesperson2.
So let’s begin!
First off you need to have admin privileges in CRM to do this.
Open the form for (LEADS in our case).
Create a new field call it Random Number as seen below.
We want the random number to be between 0 and 100 but the code we will use will generate a number that never equals zero. Place this field on your form somewhere so you can make sure it is working later, you can always hide it after that.
Ok, now we need to go to form properties and create a new script item and event handler. So go to form properties by clicking in the upper tool bar on the form page.
Under the "events" tab add a new library, click "add" then "new" on the look up window. Call it randomnumber or something like that.
Save it and it should default to the web resource you just created. This is when you put the code in:
function RandomNumber()
{
var num = Math.floor(Math.random()*102);
Xrm.Page.getAttribute("new_randomnumber").setValue(num);
}
What this code is doing is taking a variable "num" and setting it to a value. "Math.random()" returns a number between 0 and 1 but never equal to them. Multiplying it by 102 gives us a number between 0 and 102. "Math.floor" rounds the result down and will be a number between 0 and 101. It will always be greater than but no equal to zero and less than but no equal to 102.
Save and close, it should default to selecting the one you just created. If not search for "new". Make sure it is highlighted and select "add".
Now add it to the below section in "events". Decide it you want it to run onload (when the form loads) or onsave (when the form is saved). Click the "add" button to add it in to events.
Make sure to put "RandomNumber" in the function field. This is where is know what to call in the script we used for the web resource.
Now save your form and publish it.
Go to a LEAD and waaalaa, you have a random number in the field.
Thanks for reading.






No comments:
Post a Comment