{"id":1039,"date":"2017-04-19T11:19:17","date_gmt":"2017-04-19T10:19:17","guid":{"rendered":"https:\/\/help.cirrus-shield.com\/docs\/developper-guide\/javascript-library\/sample-code-example\/"},"modified":"2020-04-06T14:47:17","modified_gmt":"2020-04-06T13:47:17","slug":"sample-code-example","status":"publish","type":"docs","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/javascript-library\/sample-code-example\/","title":{"rendered":"Sample Code Example"},"content":{"rendered":"\n<p>This example will show the JavaScript code of a custom button that converts a Lead to a Contact\/Account based on the following scenario:<\/p>\n<p>If the Company field is empty then display an alert: &#8220;The field Company should not be empty if you want to convert this lead&#8221;If the lead Company field is empty then display an alert: &#8220;The field Company should not be empty if you want to convert this lead&#8221;If the lead email field is empty then display an alert: &#8220;The field Email should not be empty if you want to convert this lead&#8221;ElseIf the account already exists (based on the name)Alert(&#8220;This account already exists in the database, do you want to overwrite theexisting account data?&#8221;)Yes: update the accountNo: do not update the accountElseInsert AccountIf the contact already exists (based on the email)Alert(&#8220;This contact already exists in the database, do you want to overwrite the existing contact data?&#8221;)Yes: update the contactNo: do not update the contactElseInsert contactSet the lead status to \u201cClosed &#8211; Converted&#8221;Link all the related Invitees, Tasks, Opportunities and Campaign Members to the Contact.<\/p>\n<pre><p>&lt;script type=\"text\/javascript\"&gt;<\/p>\n<p style=\"padding-left: 30px;\">function ConvertLead() {<\/p>\n<p style=\"padding-left: 60px;\">\/\/ Get lead infovar lead = GetDataByID(GetRecordGUID(), \"Lead\", \"Id, Name, Revenue, Last_Call_Made_On, City, Company, Company_Number, Country, Email, Email_Read, First_Name, Industry, Last_Email_Sent_On, Last_Name, Lead_Origin, Mobile, No_of_Employees, Rating, Skype, Status, Street, Title, Website, Phone, ZIP, Picture, Rating, Twitter, Salutation, Department,\u00a0 Secondary_Email, Description, Email_Opt_Out, Do_Not_Call, Fax, Middle_Name, OwnerId\");<\/p>\n<p style=\"padding-left: 60px;\">\/\/ Check lead company if emptyif (lead.Company == null) {<\/p>\n<p style=\"padding-left: 90px;\">alert(GetRecordGUID() + \" - The field Company should not be empty if you want to convert this lead.\");<\/p>\n<p style=\"padding-left: 90px;\">return;<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p>\u00a0<\/p>\n<p style=\"padding-left: 60px;\">\/\/ Check lead email if emptyif (lead.Email == null) {<\/p>\n<p style=\"padding-left: 90px;\">alert(GetRecordGUID() + \" - The field Email should not be empty if you want to convert this lead.\");<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0return;<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 60px;\">\/\/ Prepare the Account Datavar xmlStrAccount = \"&lt;Data&gt;\";xmlStrAccount += \"&lt;Account&gt;\";xmlStrAccount += \"&lt;Name&gt;\";xmlStrAccount += htmlDecode(lead.Company);xmlStrAccount += \"&lt;\/Name&gt;\";xmlStrAccount += \"&lt;Company_Number&gt;\";xmlStrAccount += htmlDecode(lead.Company_Number);xmlStrAccount += \"&lt;\/Company_Number&gt;\";if (lead.Industry != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Industry&gt;\";xmlStrAccount += htmlDecode(lead.Industry);xmlStrAccount += \"&lt;\/Industry&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Phone != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Phone&gt;\";xmlStrAccount += lead.Phone;xmlStrAccount += \"&lt;\/Phone&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Fax != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Fax&gt;\";xmlStrAccount += lead.Fax;xmlStrAccount += \"&lt;\/Fax&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 60px;\">if (lead.No_of_Employees != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;No_of_Employees&gt;\";xmlStrAccount += lead.No_of_Employees;xmlStrAccount += \"&lt;\/No_of_Employees&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Email != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Email&gt;\";xmlStrAccount += lead.Email;xmlStrAccount += \"&lt;\/Email&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Revenue != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Revenue&gt;\";xmlStrAccount += lead.Revenue;xmlStrAccount += \"&lt;\/Revenue&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Website != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Website&gt;\";xmlStrAccount += lead.Website;xmlStrAccount += \"&lt;\/Website&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Description != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Description&gt;\";xmlStrAccount += htmlDecode(lead.Description);xmlStrAccount += \"&lt;\/Description&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Street != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Billing_Street&gt;\";xmlStrAccount += htmlDecode(lead.Street);xmlStrAccount += \"&lt;\/Billing_Street&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Country != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Billing_Country&gt;\";xmlStrAccount += htmlDecode(lead.Country);xmlStrAccount += \"&lt;\/Billing_Country&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.City != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Billing_City&gt;\";xmlStrAccount += htmlDecode(lead.City);xmlStrAccount += \"&lt;\/Billing_City&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.ZIP != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Billing_ZIP&gt;\";xmlStrAccount += lead.ZIP;xmlStrAccount += \"&lt;\/Billing_ZIP&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Lead_Origin != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Lead_Origin&gt;\";xmlStrAccount += htmlDecode(lead.Lead_Origin);xmlStrAccount += \"&lt;\/Lead_Origin&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 60px;\">if (lead.Rating != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;Rating&gt;\";xmlStrAccount += htmlDecode(lead.Rating);xmlStrAccount += \"&lt;\/Rating&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p style=\"padding-left: 90px;\">xmlStrAccount += \"&lt;OwnerId&gt;\";xmlStrAccount += GetOwner(lead.OwnerId);xmlStrAccount += \"&lt;\/OwnerId&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">var strname = \"\";var strfirstname = \"\";var strlastname = \"\";if (lead.First_Name != null) {<\/p>\n<p style=\"padding-left: 120px;\">strname = htmlDecode(lead.First_Name);strfirstname = htmlDecode(lead.First_Name);<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">if (lead.Last_Name != null) {<\/p>\n<p style=\"padding-left: 150px;\">strfirstname = htmlDecode(lead.Last_Name);<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Last_Name != null) {<\/p>\n<p style=\"padding-left: 120px;\">strname = strname + ' ' + htmlDecode(lead.Last_Name);strlastname = htmlDecode(lead.Last_Name);<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">strlastname = htmlDecode(lead.Name);<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (strname == \"\") {<\/p>\n<p style=\"padding-left: 120px;\">strname = htmlDecode(lead.Name);<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (strfirstname == \"\") {<\/p>\n<p style=\"padding-left: 30px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 strfirstname = htmlDecode(lead.Name);<\/p>\n<p style=\"padding-left: 60px;\">\u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Prepare the Contact Datavar xmlStrContact = \"&lt;Data&gt;\";xmlStrContact += \"&lt;Contact&gt;\";xmlStrContact += \"&lt;Name&gt;\";xmlStrContact += strname;xmlStrContact += \"&lt;\/Name&gt;\";xmlStrContact += \"&lt;First_Name&gt;\";xmlStrContact += strfirstname;xmlStrContact += \"&lt;\/First_Name&gt;\";xmlStrContact += \"&lt;Last_Name&gt;\";xmlStrContact += strlastname;xmlStrContact += \"&lt;\/Last_Name&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Title != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Title&gt;\";xmlStrContact += htmlDecode(lead.Title);xmlStrContact += \"&lt;\/Title&gt;\";<\/p>\n<p style=\"padding-left: 60px;\">\u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Mobile != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Mobile&gt;\";xmlStrContact += lead.Mobile;xmlStrContact += \"&lt;\/Mobile&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Middle_Name != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Middle_Name&gt;\";xmlStrContact += htmlDecode(lead.Middle_Name);xmlStrContact += \"&lt;\/Middle_Name&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Skype != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Skype&gt;\";xmlStrContact += htmlDecode(lead.Skype);xmlStrContact += \"&lt;\/Skype&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Email != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Email&gt;\";xmlStrContact += lead.Email;xmlStrContact += \"&lt;\/Email&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Phone != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Work_Phone&gt;\";xmlStrContact += lead.Phone;xmlStrContact += \"&lt;\/Work_Phone&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Fax != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Fax&gt;\";xmlStrContact += lead.Fax;xmlStrContact += \"&lt;\/Fax&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Street != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Street&gt;\";xmlStrContact += htmlDecode(lead.Street);xmlStrContact += \"&lt;\/Street&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Country != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Country&gt;\";xmlStrContact += htmlDecode(lead.Country);xmlStrContact += \"&lt;\/Country&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.City != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;City&gt;\";xmlStrContact += htmlDecode(lead.City);xmlStrContact += \"&lt;\/City&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.ZIP != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;ZIP&gt;\";xmlStrContact += lead.ZIP;xmlStrContact += \"&lt;\/ZIP&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (lead.Last_Email_Sent_On != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Last_Email_Sent_On&gt;\";xmlStrContact += lead.Last_Email_Sent_On; \/\/ DatexmlStrContact += \"&lt;\/Last_Email_Sent_On&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 30px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (lead.Email_Read != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Email_Read&gt;\";xmlStrContact += lead.Email_Read;xmlStrContact += \"&lt;\/Email_Read&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Do_Not_Call != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Do_Not_Call&gt;\";xmlStrContact += lead.Do_Not_Call;xmlStrContact += \"&lt;\/Do_Not_Call&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Email_Opt_Out != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Email_Opt_Out&gt;\";xmlStrContact += lead.Email_Opt_Out;xmlStrContact += \"&lt;\/Email_Opt_Out&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Lead_Origin != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Lead_Origin&gt;\";xmlStrContact += htmlDecode(lead.Lead_Origin);xmlStrContact += \"&lt;\/Lead_Origin&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 60px;\">\u00a0 \u00a0 \u00a0 if (lead.Rating != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Rating&gt;\";xmlStrContact += htmlDecode(lead.Rating);xmlStrContact += \"&lt;\/Rating&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 if (lead.Picture != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Picture&gt;\";xmlStrContact += lead.Picture;xmlStrContact += \"&lt;\/Picture&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0if (lead.Twitter != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Twitter&gt;\";xmlStrContact += htmlDecode(lead.Twitter);xmlStrContact += \"&lt;\/Twitter&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/p>\n<p style=\"padding-left: 30px;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (lead.Salutation != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Salutation&gt;\";xmlStrContact += htmlDecode(lead.Salutation);xmlStrContact += \"&lt;\/Salutation&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 60px;\">\u00a0 \u00a0 if (lead.Department != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Department&gt;\";xmlStrContact += htmlDecode(lead.Department);xmlStrContact += \"&lt;\/Department&gt;\";<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Secondary_Email != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrContact += \"&lt;Secondary_Email&gt;\";xmlStrContact += lead.Secondary_Email;xmlStrContact += \"&lt;\/Secondary_Email&gt;\";}<\/p>\n<p style=\"padding-left: 90px;\">if (lead.Description != null) {<\/p>\n<p style=\"padding-left: 90px;\">xmlStrContact += \"&lt;Description&gt;\";xmlStrContact += htmlDecode(lead.Description);xmlStrContact += \"&lt;\/Description&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 60px;\">\u00a0 \u00a0 if (lead.Last_Call_Made_On != null) {<\/p>\n<p style=\"padding-left: 120px;\">xmlStrContact += \"&lt;Last_Call_Made_On&gt;\";xmlStrContact += lead.Last_Call_Made_On; \/\/ DatexmlStrContact += \"&lt;\/Last_Call_Made_On&gt;\";<\/p>\n<p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0}<\/p>\n<p style=\"padding-left: 90px;\">xmlStrContact += \"&lt;OwnerId&gt;\";xmlStrContact += GetOwner(lead.OwnerId);xmlStrContact += \"&lt;\/OwnerId&gt;\";<\/p>\n<p style=\"padding-left: 30px;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0var AccountGUID = \"\";<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Check if Account exists based on Name valuevar Account = GetDataByColumn(\"Name\", lead.Company, \"Account\", \"Id, Name\");if (Account != null) {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Set the Account GUIDAccountGUID = Account.Id;if (confirm(\"This account already exists in the database, do you want to overwrite the existing account data?\")) {<\/p>\n<p style=\"padding-left: 150px;\">xmlStrAccount += \"&lt;\/Account&gt;\";xmlStrAccount += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update AccountUpdateRecord(\"Account\", \"Name\", xmlStrAccount);\/\/if (!success) {\/\/ return;\/\/}<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Add the Remaining XML dataxmlStrAccount += \"&lt;IsDeleted&gt;\";xmlStrAccount += 0;xmlStrAccount += \"&lt;\/IsDeleted&gt;\";xmlStrAccount += \"&lt;\/Account&gt;\";xmlStrAccount += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Insert Accountvar ObjResAccount = CreateRecord(\"Account\", \"Name\", xmlStrAccount);AccountGUID = ObjResAccount.RecordGUID;if (AccountGUID == null) {<\/p>\n<p style=\"padding-left: 180px;\">return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 150px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Check if Contact exists based on Email valuevar ContactGUID = \"\";var Contact = GetDataByColumn(\"Email\", lead.Email, \"Contact\", \"Id\");if (Contact != null) {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Set the Contact GUIDContactGUID = Contact.Id;if (confirm(\"This contact already exists in the database, do you want to overwrite the existing contact data?\")) {<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Add Contact Id to the XML dataxmlStrContact += \"&lt;Id&gt;\";xmlStrContact += Contact.Id;xmlStrContact += \"&lt;\/Id&gt;\";xmlStrContact += \"&lt;Account&gt;\";xmlStrContact += htmlDecode(lead.Company);xmlStrContact += \"&lt;\/Account&gt;\";xmlStrContact += \"&lt;\/Contact&gt;\";xmlStrContact += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update ContactUpdateRecord(\"Contact\", \"Email\", xmlStrContact);<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">else {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Add the Remaining XML dataxmlStrContact += \"&lt;Account&gt;\";xmlStrContact += htmlDecode(lead.Company);xmlStrContact += \"&lt;\/Account&gt;\";xmlStrContact += \"&lt;IsDeleted&gt;\";xmlStrContact += 0;xmlStrContact += \"&lt;\/IsDeleted&gt;\";xmlStrContact += \"&lt;\/Contact&gt;\";xmlStrContact += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Insert Contactvar ObjResContact = CreateRecord(\"Contact\", \"Email\", xmlStrContact);ContactGUID = ObjResContact.RecordGUID;<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 150px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ ---------- Update lead status to Converted ---------- \/\/<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Prepare the Lead Datavar xmlStrLead = \"&lt;Data&gt;\";xmlStrLead += \"&lt;Lead&gt;\";xmlStrLead += \"&lt;Id&gt;\";xmlStrLead += GetRecordGUID();xmlStrLead += \"&lt;\/Id&gt;\";xmlStrLead += \"&lt;Status&gt;\";xmlStrLead += \"Closed_Converted\";xmlStrLead += \"&lt;\/Status&gt;\";xmlStrLead += \"&lt;\/Lead&gt;\";xmlStrLead += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Update LeadUpdateRecord(\"Lead\", \"Id\", xmlStrLead);<\/p>\n<p style=\"padding-left: 120px;\">\/\/ Refresh the pagelocation.reload();<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 120px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Get All the related Inviteevar Invitee = GetDataByColumn(\"Lead\", GetRecordGUID(), \"Invitee\", \"Id\");if (Invitee != null) {<\/p>\n<p style=\"padding-left: 120px;\">if (Invitee.length != undefined) {<\/p>\n<p style=\"padding-left: 150px;\">for (var i = 0; i &lt; Invitee.length; i++) {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Prepare the Invitee Data and link it to the contactvar xmlStrInvitee = \"&lt;Data&gt;\";xmlStrInvitee += \"&lt;Invitee&gt;\";xmlStrInvitee += \"&lt;Id&gt;\";xmlStrInvitee += Invitee[i].Id;xmlStrInvitee += \"&lt;\/Id&gt;\";xmlStrInvitee += \"&lt;Contact&gt;\";xmlStrInvitee += lead.Email;xmlStrInvitee += \"&lt;\/Contact&gt;\";xmlStrInvitee += \"&lt;\/Invitee&gt;\";xmlStrInvitee += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 210px;\">\/\/ Update InviteeUpdateRecord(\"Invitee\", \"Id\", xmlStrInvitee);<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 180px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 210px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else \/\/ one record<\/p>\n<p style=\"padding-left: 120px;\">{<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Prepare the Invitee Data and link it to the contactvar xmlStrInvitee = \"&lt;Data&gt;\";xmlStrInvitee += \"&lt;Invitee&gt;\";xmlStrInvitee += \"&lt;Id&gt;\";xmlStrInvitee += Invitee.Id;xmlStrInvitee += \"&lt;\/Id&gt;\";xmlStrInvitee += \"&lt;Contact&gt;\";xmlStrInvitee += lead.Email;xmlStrInvitee += \"&lt;\/Contact&gt;\";xmlStrInvitee += \"&lt;\/Invitee&gt;\";xmlStrInvitee += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update InviteeUpdateRecord(\"Invitee\", \"Id\", xmlStrInvitee);<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Get All the related Tasksvar Tasks = GetDataByColumn(\"Lead\", GetRecordGUID(), \"Task\", \"Id\");if (Tasks != null) {<\/p>\n<p style=\"padding-left: 120px;\">if (Tasks.length != undefined) {<\/p>\n<p style=\"padding-left: 150px;\">for (var i = 0; i &lt; Tasks.length; i++) {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Prepare the Task Data and link it to the contactvar xmlStrTask = \"&lt;Data&gt;\";xmlStrTask += \"&lt;Task&gt;\";xmlStrTask += \"&lt;Id&gt;\";xmlStrTask += Tasks[i].Id;xmlStrTask += \"&lt;\/Id&gt;\";xmlStrTask += \"&lt;Contact&gt;\";xmlStrTask += lead.Email;xmlStrTask += \"&lt;\/Contact&gt;\";xmlStrTask += \"&lt;Account&gt;\";xmlStrTask += htmlDecode(lead.Company);xmlStrTask += \"&lt;\/Account&gt;\";xmlStrTask += \"&lt;\/Task&gt;\";xmlStrTask += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 210px;\">\/\/ Update TaskUpdateRecord(\"Task\", \"Id\", xmlStrTask);<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 180px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 210px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else \/\/ one record<\/p>\n<p style=\"padding-left: 120px;\">{<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Prepare the Task Data and link it to the contactvar xmlStrTask = \"&lt;Data&gt;\";xmlStrTask += \"&lt;Task&gt;\";xmlStrTask += \"&lt;Id&gt;\";xmlStrTask += Tasks.Id;xmlStrTask += \"&lt;\/Id&gt;\";xmlStrTask += \"&lt;Contact&gt;\";xmlStrTask += lead.Email;xmlStrTask += \"&lt;\/Contact&gt;\";xmlStrTask += \"&lt;Account&gt;\";xmlStrTask += htmlDecode(lead.Company);xmlStrTask += \"&lt;\/Account&gt;\";xmlStrTask += \"&lt;\/Task&gt;\";xmlStrTask += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update TaskUpdateRecord(\"Task\", \"Id\", xmlStrTask);<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Get All the related Opportunitiesvar Opportunities = GetDataByColumn(\"Lead\", GetRecordGUID(), \"Opportunity\", \"Id\");if (Opportunities != null) {<\/p>\n<p style=\"padding-left: 120px;\">if (Opportunities.length != undefined) {<\/p>\n<p style=\"padding-left: 150px;\">for (var i = 0; i &lt; Opportunities.length; i++) {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Prepare the Opportunity Data and link it to the contactvar xmlStrOpportunity = \"&lt;Data&gt;\";xmlStrOpportunity += \"&lt;Opportunity&gt;\";xmlStrOpportunity += \"&lt;Id&gt;\";xmlStrOpportunity += Opportunities[i].Id;xmlStrOpportunity += \"&lt;\/Id&gt;\";xmlStrOpportunity += \"&lt;Main_Contact&gt;\";xmlStrOpportunity += lead.Email;xmlStrOpportunity += \"&lt;\/Main_Contact&gt;\";xmlStrOpportunity += \"&lt;Account&gt;\";xmlStrOpportunity += htmlDecode(lead.Company);xmlStrOpportunity += \"&lt;\/Account&gt;\";xmlStrOpportunity += \"&lt;\/Opportunity&gt;\";xmlStrOpportunity += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 210px;\">\/\/ Update OpportunityUpdateRecord(\"Opportunity\", \"Id\", xmlStrOpportunity);<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 180px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 210px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else \/\/ one record<\/p>\n<p style=\"padding-left: 120px;\">{<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Prepare the Opportunity Data and link it to the contactvar xmlStrOpportunity = \"&lt;Data&gt;\";xmlStrOpportunity += \"&lt;Opportunity&gt;\";xmlStrOpportunity += \"&lt;Id&gt;\";xmlStrOpportunity += Opportunities.Id;xmlStrOpportunity += \"&lt;\/Id&gt;\";xmlStrOpportunity += \"&lt;Main_Contact&gt;\";xmlStrOpportunity += lead.Email;xmlStrOpportunity += \"&lt;\/Main_Contact&gt;\";xmlStrOpportunity += \"&lt;Account&gt;\";xmlStrOpportunity += htmlDecode(lead.Company);xmlStrOpportunity += \"&lt;\/Account&gt;\";xmlStrOpportunity += \"&lt;\/Opportunity&gt;\";xmlStrOpportunity += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update OpportunityUpdateRecord(\"Opportunity\", \"Id\", xmlStrOpportunity );<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 90px;\">\/\/ Get All the related Campaign Membersvar CampaignMembers = GetDataByColumn(\"Lead\", GetRecordGUID(), \"Campaign_Member\", \"Id\");if (CampaignMembers != null) {<\/p>\n<p style=\"padding-left: 120px;\">if (CampaignMembers.length != undefined) {<\/p>\n<p style=\"padding-left: 150px;\">for (var i = 0; i &lt; CampaignMembers.length; i++) {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Prepare the Campaign Member Data and link it to the contactvar xmlStrCampaignMember = \"&lt;Data&gt;\";xmlStrCampaignMember += \"&lt;Campaign_Member&gt;\";xmlStrCampaignMember += \"&lt;Id&gt;\";xmlStrCampaignMember += CampaignMembers[i].Id;xmlStrCampaignMember += \"&lt;\/Id&gt;\";xmlStrCampaignMember += \"&lt;Contact&gt;\";xmlStrCampaignMember += lead.Email;xmlStrCampaignMember += \"&lt;\/Contact&gt;\";xmlStrCampaignMember += \"&lt;\/Campaign_Member&gt;\";xmlStrCampaignMember += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 210px;\">\/\/ Update Campaign MemberUpdateRecord(\"Campaign_Member\", \"Id\", xmlStrCampaignMember);<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 180px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 210px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 180px;\">}<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 120px;\">else \/\/ one record<\/p>\n<p style=\"padding-left: 120px;\">{<\/p>\n<p style=\"padding-left: 150px;\">\/\/ Prepare the Campaign Member Data and link it to the contactvar xmlStrCampaignMember = \"&lt;Data&gt;\";xmlStrCampaignMember += \"&lt;Campaign_Member&gt;\";xmlStrCampaignMember += \"&lt;Id&gt;\";xmlStrCampaignMember += CampaignMembers.Id;xmlStrCampaignMember += \"&lt;\/Id&gt;\";xmlStrCampaignMember += \"&lt;Contact&gt;\";xmlStrCampaignMember += lead.Email;xmlStrCampaignMember += \"&lt;\/Contact&gt;\";xmlStrCampaignMember += \"&lt;\/Campaign_Member&gt;\";xmlStrCampaignMember += \"&lt;\/Data&gt;\";try {<\/p>\n<p style=\"padding-left: 180px;\">\/\/ Update Campaign MemberUpdateRecord(\"Campaign_Member\", \"Id\", xmlStrCampaignMember);<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 150px;\">catch (ex) {<\/p>\n<p style=\"padding-left: 180px;\">alert(ex.message);return;<\/p>\n<p style=\"padding-left: 150px;\">}<\/p>\n<p style=\"padding-left: 120px;\">}<\/p>\n<p style=\"padding-left: 90px;\">}<\/p>\n<p style=\"padding-left: 60px;\">}<\/p>\n<p>&lt;\/script&gt;<\/p>\n<p><!-- 9ff1dc056826768a4ed5fd1f30c8a9f1 --><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":945,"menu_order":26,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_tag":[],"class_list":["post-1039","docs","type-docs","status-publish","hentry"],"comment_count":0,"_links":{"self":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/1039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/comments?post=1039"}],"version-history":[{"count":25,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/1039\/revisions"}],"predecessor-version":[{"id":4138,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/1039\/revisions\/4138"}],"up":[{"embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/945"}],"next":[{"title":"toCurrentUserTimezone","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/javascript-library\/tocurrentusertimezone\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3544"}],"prev":[{"title":"Format Date Time","link":"https:\/\/help.cirrus-shield.com\/en\/docs\/developer-guide\/javascript-library\/format-date-time\/","href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/docs\/3507"}],"wp:attachment":[{"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/media?parent=1039"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/help.cirrus-shield.com\/en\/wp-json\/wp\/v2\/doc_tag?post=1039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}