Sunday, October 3, 2010

Validate/Restrict Convert Lead functionality

On of my colleague had a requirement of restricting ConvertLead based on a pick-list in lead form (restrict to convert it to account\contact based on pick-list value). Finally event.Mode did the trick for me to achieve it.

You can obtain the values in ConvertLead dialog box by tracing its event.Mode value (=16). Below is the code sample for reference.

Screenshot walk-through:

JavaScript Code:

OnSave Event

if(event.Mode == 16) //Event when Lead is Qualified.
{
var createAccount = crmFormSubmit.qlCreateAccount.value;
var createContact = crmFormSubmit.qlCreateContact.value;
var customerType = crmForm.all.new_type.DataValue; //You can obtain lead for attribute values
if(customerType = 1 && createContact == 'true')
{
alert("Lead's customer type is Account, hence it cannot be converted into Contact.\nPlease uncheck Contact in ConvertLead dialog box and try again.");
event.returnValue = false;
return false;
}
else if(customerType = 2 && createContact == 'true')
{
alert("Lead's customer type is Contact, hence it cannot be converted into Account.\nPlease uncheck Account in ConvertLead dialog box and try again.");
event.returnValue = false;
return false;
}
}

Reference:

You can access the values in ConvertLead dialog box as below

event.Mode = 16 (Lead Qualify)

ObjectType = crmFormSubmit.crmFormSubmitObjectType.value
FormSecurity = crmFormSubmit.crmFormSubmitSecurity.value
Account (check/uncheck) = crmFormSubmit.qlCreateAccount.value
Contact (check/uncheck) = crmFormSubmit.qlCreateContact.value
Opportunity (check/uncheck) = crmFormSubmit.qlCreateOpportunity.value
Currency = crmFormSubmit.qlOppCurrencyId.value
ShowNewRecords (checkbox) = crmFormSubmit.qlShowNew.value
Customer type = crmFormSubmit.qlOpportunityParentType.value
Customer id = crmFormSubmit.qlOpportunityParentId.value

event.Mode = 15 (Lead Disqualify)

Status = crmFormSubmit.ulNewStatus.value

No comments:

Post a Comment