I am trying to automatically create a lead from an incoming email. The default js templates can very easily file the email as a new communication, but I want to modify this to file as a new lead rather. I know it can be done and if anyone has any samples or leads for me it would be greatly appreciated.
Below is some outline code. The main function that is called is SalesEnquiry. You'll see that it check whether the senders email address is known. If it is unknown then it creates a lead.
// Email Manager Template file.
// 6 objects are passed in to the scripts namespace.
// 1. UserQuery - eWareQuery object that contains the details of the user who sent the email...should there be one.
// 2. PersonQuery - eWareQuery object that contains the person details of the sender of the email
// 3. CompanyQuery - eWareQuery object that contains the company details of the sender of the email
// 4. eWare - eWare object itself...logged on with admin user
// 5. MsgHandler - The log function (To catch errors) is only used from this object
// eg MsgHandler.Log("This text will appear in the log file");
// eg MsgHandler.FeedbackOnSuccess indicates whether Feedback On Success is enabled
// eg MsgHandler.FeedbackOnFailure indicates whether Feedback On Failure is enabled
// 6. eMail - This is the interface to the email itself
// *NOTE* for user (the senders) security to apply you must create your own eware object and logon as that user using their
//must be set to true for the MsgHandler.Log method to work.
MsgHandler.Debug = true;
// Initialise Variables
CRM = eWare;
var mydate = new Date();
///Variables to allow data to be passed between functions
var intCommRecordID = 0;
var intOppoRecordID = 0;
var intLeadRecordID = 0;
var intCaseRecordID = 0;
// Start Main Functions
//function name must exist in translations (custom_caption) table
MsgHandler.Log("SalesEnquiry function called");
//check if person exists
// Start Utility Functions
var myRecord = CRM.CreateRecord("lead");
myRecord.lead_Description= eMail.Subject.substring(0, 39);
myRecord.lead_Details= "Please see the attached email";
myRecord.lead_Status= "In Progress";
myRecord.lead_Opened = mydate.getVarDate();
myRecord.SetWorkflowInfo("Lead Workflow", "Assigned")
intLeadRecordID = myRecord.lead_leadid;
If a communication record is also created, how can it be properly linked to the new Lead Record?
A communication has a field comm_leadid. If you create a communication record (and a comm_link record) you just need to link the communication to the lead.
© The Sage Group plc 2017All Rights Reserved