If you want to covert the lead to some other entity, for example, to a custom entity, it’s impossible with standard convert page. When I came across this requirement, I implemented a solution without the standard page.
This solution was flexible, but contained few steps.
1) Hide the button to the standard lead convert page.
2) Add my own menu system to lead entity
3) Implement disqualify method
4) Implement qualify(convert) method
Will consider the steps in detail;
1) Hide the button to the standard lead convert page.
I could call below method to hide the lead convert button.
hideStandardQualifyingButton = function() { var lis = document.getElementsByTagName('LI'); var i = 0; while (i < lis.length) { if (lis[i].getAttribute('title') == 'Qualify or disqualify the lead') { //lis[i].outerHTML = '<SPAN></SPAN>' this gives errors for resizing the window afterwords lis[i].outerHTML = '<SPAN> <SPAN> <SPAN> <SPAN> </SPAN> </SPAN> </SPAN> </SPAN>'; } i = i + 1; } }
If you check the web, you will see few places that suggest this code with the line I have commented. That works fine, but throws a page error when user resizes the browser window. Then the next line was introduced, instead.
2) Add my own menu system to lead entity
If you have play around with ISV file, this won’t be a hard task. Below are the new entries in lead entity for this.
<CustomMenus> <Menu> <Titles> <Title LCID="1033" Text="Lead Conversion" /> </Titles> <MenuItem JavaScript="LeadQualify();"> <Titles> <Title LCID="1033" Text="Lead Convert" /> </Titles> </MenuItem> <SubMenu> <Titles> <Title LCID="1033" Text="Disqualify" /> </Titles> <MenuItem JavaScript="LeadDisQualify(4);"> <Titles> <Title LCID="1033" Text="Already Known" /> </Titles> </MenuItem> <MenuItem JavaScript="LeadDisQualify(6);"> <Titles> <Title LCID="1033" Text="No Longer Interested" /> </Titles> </MenuItem> </SubMenu> </Menu> </CustomMenus>
3) Implement disqualify method
This is the simple code you can use to disqualify the lead. ReasonCode is the integer value of disqualification reason.
oService.SetState("lead", _leadid, "Disqualified", ReasonCode);
If you want to further extend the disqualifying reasons, it’s possible. You can simply add whatever the new entries in entity in the standard way as below.
Now you can pass the relevant values to the same method. (Of course you need to add/edit the menu items in step 2 accordingly)
4) Implement qualify(convert) method
This is where you get the real fruit of the exercise. Now you can programmatically do your steps to convert your lead to any entity, including your own custom entities. For example this is a simple code I used to convert the lead to a custom entity called regional project (new_regionalproject).
var _leadid = crmForm.ObjectId; var _bEntity = new BusinessEntity("new_regionalproject"); _bEntity.attributes["originatingleadid"] = _leadid; _bEntity.attributes["firstname"] = _firstName; _bEntity.attributes["lastname"] = _lastName; .... .... return _oService.Create(_bEntity);
Now we need to change state of the lead to qualified.
oService.SetState("lead", _leadid, "Qualified", 3);
Notes:
1) In step 4, you can actually implement any business logic since you are free to write the code before qualifying the lead. You can even Update or Associate with other entities accordingly.
For example I have converted the lead to account and created a Quote (without Quote products) using particular account as the potential customer.
2) In qualifying/disqualifying, you got to use the given methods. (i.e. SetState) Don’t try to call Update method here Since its not allowed.
Hope this will help you.
I need to do exactly this in crm 2011. I want to use javascript. Can you help please?
ReplyDeleteYep, you can do this in crm2011 too.
ReplyDeleteFor JavaScript operation I use Ascentium CrmService. Please check http://www.avanadeblog.com/xrm/2010/05/a-microsoft-dynamics-crm-javascript-sdk-in-celebration-of-an-amazing-year-.html to find out more on how to use those operations.
Also this page contains link to download the Ascentium CrmService. It is just one file called CrmService.js. Once you add it to your form as a web resource you are ready to do any operation. Your set state operation will be like this;
var oService = new Ascentium_CrmService(null, null);
oService.SetState("lead", _leadid, "Qualified", 3);
If you need further clarification or any other information pl let me know send your mail address.
Great article but I am not able to find the webservice you mentioned. I am sending you my email. Can you please send it to me to make it work for crm 2011 ? thanks so much in advance.
ReplyDeleteHi Syed, I didnt get your email address. Please pass it.. or send a mail to my mail address sumedha7@gmail.com I can send the js library and etc.
ReplyDelete