Converting a lead to a contractor with a script
This is an example of a script for converting a lead to a contractor (Contractor type - Company).
Script with PublicAPI
Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA up to 3.12.1 inclusive.
Context variables:
context.Lead - Lead type variableNamespace:
Script:
using EleWise.ELMA.API;
var contractor = PublicAPI.CRM.Lead.ConvertLeadToContractorLegal(context.Lead);
Script without PublicAPI
Context variables:
context.Lead - Lead variable, type - Lead object
context.Contractor - Contractor variable, type - Contractor object
Add the following assembly:
Elewise.ELMA.CRM
Namespaces:
using EleWise.ELMA.CRM;
using EleWise.ELMA.CRM.Managers;
using EleWise.ELMA.CRM.Models;
using EleWise.ELMA.Model.Entities;
using EleWise.ELMA.Model.Managers;
using EleWise.ELMA.Model.Mappings;
using EleWise.ELMA.Model.Services;
using EleWise.ELMA.Services;
Script text:
var lead=context.Lead;
var contractorUid = InterfaceActivator.UID<IContractorLegal>();
var entityType = Locator.GetService<IMetadataRuntimeService>().GetTypeByUid(contractorUid);
var contractor = (IContractor)InterfaceActivator.Create(entityType);
var map = LeadManager.Instance.ConvertToContractorMap(contractor.GetType());
PropertyMapHelper.Map(lead, contractor, map);
var map1 = LeadManager.Instance.ConvertToContactMap();
contractor.Contacts.Clear();
foreach (var leadContact in lead.Contacts)
{
var contact = InterfaceActivator.Create<IContact>();
PropertyMapHelper.Map(leadContact, contact, map1);
contact.Contractor = contractor;
contractor.Contacts.Add(contact);
}
LeadManager.Instance.ConvertComplete(lead, contractor, contractor.Contacts, null, null, null);
context.Contractor=(Contractor)contractor;