Description
Create a custom HTML template which will be used in an iframe to publish in the corporate website: Add proper validation to the form,add the validation for the Product of interest to select at least one of them. Use Bootstrap for from development
The lead should be created as company with the person added as a contact (contact name, contact role, contact phone, contact email).
Contact Role, Product of interested and additional Information should be saved as user notes.
Update code to add a new contact if the company already exists.
JS File for contact Form
var create_lead = //the corresponding external url used for suitelt
var Home_Url = //Redirect link to added here
var DataObj = {}
DataObj["productOfinter"] = {}
contactRoleSearch('contactRoleSearch');
function contactRoleSearch(data) {
if (data == 'contactRoleSearch') {
var cb = 'createSelect'
console.log(create_lead + "&GetValue=contactRoleSearch" + "&apitype=do_ContactSearch" + "&callback=" + cb);
var u = create_lead + "&GetValue=contactRoleSearch" + "&apitype=do_ContactSearch" + "&callback=" + cb;
//showloading("Loading...",3000);
getJSONP(u);
} else {
var flag = true
if ((Object.keys(DataObj["productOfinter"]).length) <= 0) {
swal({
title: "",
text: "Please select atleast one of the Product of Interest options",
type: "info"
});
flag = false;
return false
}
if (flag) {
var cb = 'submitFormFn'
console.log(create_lead + "&GetValue=" + data + "&apitype=do_ContactSearch&data=" + JSON.stringify(DataObj) + "&callback=" + cb);
var u = create_lead + "&GetValue=" + data + "&apitype=do_ContactSearch&data=" + JSON.stringify(DataObj) + "&callback=" + cb;
showloading("Loading...");
getJSONP(u);
} else {
swal({
title: "",
text: "Please fill the required fields",
type: "info"
});
}
}
}
function createSelect(result) {
//console.log("createSelect call back", result);
result = JSON.parse(result);
console.log('check test', result);
var Contact_RoleSelect = '<select class="form_element2 choose" name="Contact Role" value="Contact Role" id="Contact Role" onchange="ContactRole(this.id)" >'
Contact_RoleSelect += '<option value="" disabled="" selected="selected">Contact Role</option>'
if (result.status == "SUCCESS") {
var setDAtaSection = result.data
for (var key in setDAtaSection) {
var options = setDAtaSection[key];
Contact_RoleSelect += '<option value="' + options.Id + '">' + options.name + '</option>'
}
Contact_RoleSelect += '</select>'
// console.log('Contact_RoleSelect', Contact_RoleSelect);
$('#Contact_RoleSelect').html(Contact_RoleSelect);
} else {
Contact_RoleSelect += '</select>'
$('#Contact_RoleSelect').html(Contact_RoleSelect);
//console.log('data', data);
swal({
title: "Warning",
text: "Something went wrong",
type: "error"
});
}
}
function ValidateEmail(value) {
console.log('ValidateEmail', value)
var email = value;
var atLoc = email.indexOf("@");
var dotLoc = email.lastIndexOf(".");
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)) {
DataObj.email = encodeURIComponent(email);
document.getElementById('e-mail-validation-msg').style = "color:white";
document.getElementById('e-mail-validation-msg').innerHTML = " ";
return (true)
}
swal({
title: "Error",
text: "You have entered an invalid email address!",
type: "error"
});
document.getElementById('e-mail').focus();
document.getElementById('e-mail-validation-msg').style = "color:red";
document.getElementById('e-mail-validation-msg').innerHTML = " : Please enter a valid email address";
return (false)
}
function IsValidPhone(phoneno) {
var x = document.getElementById(phoneno).value;
console.log("phone", x);
var patt1 = /[0-9]/g;
var result = x.match(patt1);
var pattern = /^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,10}$/im;
// var pattern = /^\+{0,2}([\-\. ])?(\(?\d{0,3}\))?([\-\. ])?\(?\d{0,3}\)?([\-\. ])?\d{3}([\-\. ])?\d{4}/;
//var isValidph= /^\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})$/.test(x);
if ((x != '') && (x != null)) {
if (x.match(pattern) && x.length < 16 && x.length > 6) {
document.getElementById('p_' + phoneno).style = "color:white";
document.getElementById('p_' + phoneno).innerHTML = " ";
DataObj.phoneno = x;
return true;
} else {
document.getElementById(phoneno).focus();
document.getElementById('p_' + phoneno).style = "color:red";
document.getElementById('p_' + phoneno).innerHTML = " : Invalid";
DataObj.phoneno = null;
return false;
}
} else {
DataObj.phoneno = x;
return true;
}
}
function sectionsubtitletablefn(e) {
var check = e.checked;
if (check) {
DataObj["productOfinter"][e.value] = e.value
} else {
if (DataObj.productOfinter[e.value])
delete DataObj.productOfinter[e.value]
}
}
function ContactRole(id) {
var sel = document.getElementById(id);
var opt = sel.options[sel.selectedIndex];
var value = opt.getAttribute('value');
if (value != "") {
DataObj.contactRole = value
} else
DataObj.contactRole = null
}
function chnageUpdate(data) {
DataObj[data.id] = data.value;
}
function submitFormFn(result) {
result = JSON.parse(result);
console.log('submitFormFn', result)
if (result) {
if (result.status == "SUCCESS") {
var setDAtaSection = result.data
if (setDAtaSection) {
swal({
title: "Notification Received Successfully",
text: "A sales associate will contact you soon.",
type: "success"
}, function() {
window.parent.window.location.href = Home_Url;
});
}
} else if (result.status == "Failure") {
swal({
title: "Warning",
text: result.data,
type: "error"
});
} else if (result.status == "Error") {
swal({
title: "Errors",
text: result.data,
type: "error"
});
} else {
swal({
title: "Error",
text: result.data,
type: "error"
});
}
} else {
swal({
title: "Error.",
text: "Something went wrong",
type: "error"
});
}
}
$(function() {
$('#contact_form').on('submit', function(e) {
e.preventDefault();
contactRoleSearch('createLead');
});
});
function showloading(title, time) {
swal({
title: title,
text: "<img width='100' src='here the Link for loading gif to be add'>",
html: true,
timer: time,
showConfirmButton: false
});
}
function SubmitLeadForm(form) {
var doc = $('#' + form);
console.log('SubmitLeadForm', form)
doc.attr("action", create_lead);
// doc.submit();
return true
}
function getJSONP(url) {
var script = document.createElement('script');
var head = document.getElementsByTagName('head')[0] || document.documentElement;
script.src = url
head.appendChild(script);
}
CSS File
/*Created for the contact form for the Users*/
html,
caption,
tbody,
tfoot,
thead,
th,
{
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
border: 0px;
vertical-align: baseline;
}
body {
font-family: Comfortaa, Arial, Helvetica, sans-serif;
margin: 0 auto;
font-size: 14px;
line-height: 24px;
}
html,
body,
{
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
h3 {
font-size: 18px;
color: #7a7a7a;
font-weight: 100;
line-height: 30px;
}
a h3 {
font-size: 18px;
color: #7a7a7a;
font-weight: 100;
line-height: 30px;
}
.default_class {
width: 100%;
margin: 2% 0%;
float: left;
font-size: 16px;
display: block;
}
.clear {
clear: both;
line-height: 0px;
}
.clearleft {
clear: left;
line-height: 0px;
}
.clearright {
clear: right;
line-height: 0px;
}
.center {
text-align: center;
}
ul {
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
border: 0px;
vertical-align: baseline;
}
.display {
display: block;
}
.left {
float: left;
}
.specs {
border: 1px dotted #CCCCCC;
}
.right {
float: right;
}
.smallfont {
font-size: 8px;
line-height: 10px;
font-style: italic;
}
#caption {
text-indent: -9999px;
line-height: 0px;
height: 0px;
font-size: 0px;
margin: 0px;
}
.contact_form {
font-size: 11px;
line-height: 22px;
}
.form_element {
width: 95%;
font-size: 10px;
line-height: 10px;
padding: 2% 2%;
}
.contactcreatebutton {
background-color: #0B63FF;
width: 20%;
height: 50px;
line-height: 50px;
color: #FFFFFF;
font-size: 17px;
text-align: center;
border: 0px;
cursor: pointer;
/* hand-shaped cursor */
cursor: hand;
/* for IE 5.x */
}
#wrap {
background-color: #FFFFFF;
}
.navtext {
width: 95%;
padding-top: 10px;
padding-left: 10px;
padding-bottom: 10px;
}
#menu li:hover div a {
font-size: 13px;
text-align: left;
padding-left: 20px;
padding-top: 5px;
padding-bottom: 5px;
color: #acadb0;
font-weight: normal;
}
#menu li:hover div a:hover {
color: #FFFFFF;
}
.form {
line-height: 25px;
font-size: 14px;
height: 25px;
padding: 0px 5px;
width: 90%;
}
.label {
padding-left: 10px;
line-height: 30px;
font-size: 11px;
}
.contact_form {
border-top: 1px solid #272828;
padding-top: 15px;
}
#contentform {
margin: 0px auto;
magin-top: 150px;
/*width: 65%;*/
padding-bottom: 10px;
padding-top: 50px;
padding-bottom: 50px;
}
.form_element2 {
float: left;
font-size: 16px;
display: block;
line-height: 20px;
margin: 15px 0;
width: 100%;
outline: none;
border: 1px solid #fff;
background-color: #f4f4f4;
border-radius: 44px !important;
display: inline-block;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.choose {
height: 60px;
padding: 15px 10px;
}
fieldset {
border: none;
}
.whole {
width: 100%;
label {
font-size: 14px;
font-weight: 600;
padding: 0 10px;
line-height: 14px;
}
}
.sectionsubtitle {
font-size: 18px;
color: #545454;
display: block;
text-align: left;
line-height: 20px;
padding-bottom: 10px;
}
.sectionsubtitletable {
margin: 0 4%;
}
.sectionsubtitlerow {
display: inline-flex;
width: 100%;
}
.sectionsubtitlecol {
display: inherit;
width: 100%;
}
.sectiontitle {
font-size: 30px;
display: block;
color: #424242;
font-weight: 100;
line-height: 40px;
text-decoration: none;
}
.contactcreatebuttonclass {
text-align: center;
}
.mandatory-star {
position: absolute;
color: red;
font-size: 15px;
top: 25px;
left: 5px;
}
@media (min-width: 236px) {
.left_container,
.right_container {
width: 6%;
}
.main_container {
width: 88%;
}
h2 {
font-size: 1.5rem;
}
.contactcreatebutton {
width: 100%;
}
label {
font-size: 10px;
padding: 0 10px;
line-height: 14px;
}
.form_element2 {
padding: 15px;
}
.choose {
height: 50px;
}
}
@media (min-width: 768px) {
.left_container,
.right_container {
width: 16.5%;
}
.main_container {
width: 67%;
}
h2 {
font-size: 2rem;
}
.contactcreatebutton {
width: 20%;
}
label {
font-size: 14px;
}
.form_element2 {
padding: 20px;
}
.choose {
height: 60px;
}
}
HTML PAGE
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500&display=swap" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Comfortaa' rel='stylesheet'>
<!-- Sweetalert min.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.js"></script>
<!-- Sweetalert min.css -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-sweetalert/1.0.1/sweetalert.min.css" media="All">
<!-- MAR-312 Lead creation : CSS : Contact Form.css -->
<link rel="stylesheet" href="">
<!-- MAR-312 Lead creation/JS/Contact Form.js -->
<script type="text/javascript" src=""></script>
<title>Contact Form</title>
</head>
<body>
<div id="contentform" class="row">
<div class="left_container"></div>
<div class="main_container">
<center>
<h2>Contact a Sales Representative</h2>
<p>Are you interested in our products and would like to speak with a sales representative?<br>Simply fill out the form below and we'll contact you as soon as possible.</p>
</center>
<form method="post" id="contact_form" class="contact_form" onsubmit="return SubmitLeadForm('contact_form')" action="">
<!-- <input type="hidden" name="Marshall Sales Inquiry" value="Leads">
<input type="hidden" name="recipient" value="eduardo.serrano@marshallelectronics.net">
<input type="hidden" name="redirect" value="http://www.marshall-usa.com/thankyou.php"> -->
<div class="row">
<div class="col-md-12">
<span class="mandatory-star">*</span>
<input name="Company" type="text" class="default_class form_element2" id="company" placeholder="Company Name" autocomplete="off" onfocus="this.value=''" onchange="chnageUpdate(this)" required="">
<span style="width: 100%; padding: 5px;"></span>
</div>
<div class="col-md-12 col-lg-6">
<span class="mandatory-star">*</span>
<input name="Firstname" type="text" class="default_class form_element2" id="firstname" placeholder="First Name" autocomplete="off" onfocus="this.value=''" onchange="chnageUpdate(this)" required="">
<span style="width: 100%; padding: 5px;"></span>
</div>
<div class="col-md-12 col-lg-6">
<span class="mandatory-star">*</span>
<input name="Lastname" type="text" class="default_class form_element2" id="lastname" placeholder="Last Name" autocomplete="off" onfocus="this.value=''" onchange="chnageUpdate(this)" required="">
<span style="width: 100%; padding: 5px;"></span>
</div>
<div class="col-md-12" id="Contact_RoleSelect">
<!-- <select class="choose" name="Contact Role" value="Contact Role" id="Contact Role">
<option value="" disabled="" selected="selected">Contact Role</option>
<option value="Primary Contact">Primary Contact</option>
<option value="Decision Maker">Decision Maker</option>
<option value="Consultant">Consultant</option>
<option value="Buyer">Buyer</option>
<option value="Alternative Contact">Alternative Contact</option>
</select> -->
<br>
</div>
<div class="col-md-12 col-lg-6">
<span class="mandatory-star">*</span>
<input name="Phonenumber" type="text" class="default_class form_element2" id="phonenumber" placeholder="Phone Number" onchange="IsValidPhone(this.id)" autocomplete="off" onfocus="this.value=''" required=""><br>
<span id="p_phonenumber"></span>
</div>
<div class="col-md-12 col-lg-6">
<span class="mandatory-star">*</span>
<input name="email" type="text" id="e-mail" class="default_class form_element2 " placeholder="Email" autocomplete="off" onchange="ValidateEmail(this.value)" onfocus="this.value=''" required="">
<br>
<span id="e-mail-validation-msg"></span>
</div>
<fieldset class="default_class" id="Products of Interest"><label class="sectionsubtitle">Products of Interest</label>
<table width="100%" class="sectionsubtitletable" id="sectionsubtitletable">
<tbody>
<tr class="sectionsubtitlerow">
<td width="40%" class="sectionsubtitlecol"><input type="checkbox" value="Cameras" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Cameras</label></td>
<td width="25%" class="sectionsubtitlecol"><input type="checkbox" value="Monitors" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Monitors</label></td>
<td width="35%" class="sectionsubtitlecol"><input type="checkbox" value="AV Hardware and Converters" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>AV Hardware and Converters</label></td>
</tr>
<tr class="sectionsubtitlerow">
<td width="40%" class="sectionsubtitlecol"><input type="checkbox" value="Remote Solutions and Web Conferencing" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Remote Solutions and Web Conferencing</label></td>
<td width="25%" class="sectionsubtitlecol"><input type="checkbox" value="Microphones" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Microphones</label></td>
<td width="35%" class="sectionsubtitlecol"><input type="checkbox" value="Optical Systems and Lens" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Optical Systems and Lens</label></td>
</tr>
<tr class="sectionsubtitlerow">
<td width="40%" class="sectionsubtitlecol"><input type="checkbox" value="Mogami Cables" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Mogami Cables</label></td>
<td width="25%" class="sectionsubtitlecol"><input type="checkbox" value="Cables/Connectors" name="Products of Interest" onchange="sectionsubtitletablefn(this)"><label>Cables/Connectors</label></td>
<td class="sectionsubtitlecol"></td>
</tr>
</tbody>
</table>
</fieldset>
<br>
<div class="col-md-12">
<textarea name="message" class="default_class form_element2 whole" id="message" onfocus="this.value=''" onchange="chnageUpdate(this)">Additional Information</textarea><br class="clearleft"><br>
</div>
</div>
<div class="contactcreatebuttonclass">
<input type="submit" class="contactcreatebutton" id="SUBMIT" value="Submit">
<input type="reset" class="contactcreatebutton" id="RESET" value="Reset">
</div>
</form>
<br class="clear">
</div>
<div class="right_container"></div>
</div>
</body>
</html>
Suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/**/
define(['N/record', 'N/file', 'N/search'], function(record, file, search) {
var DATA = {};
var UsrCallback
//To check whether a value exists in parameter
function checkForParameter(parameter, parameterName) {
if (parameter !== null && parameter !== undefined && parameter !== false && parameter !== "null" && parameter !== "undefined" && parameter !== "false" && parameter != "" && parameter != " ")
return true;
if (parameterName)
log.error("Empty Value found", "Empty Value for parameter " + parameterName);
return false;
}
//To assign a default value if the it is empty
function assignDefaultValue(value, defaultValue) {
if (checkForParameter(value)) return value;
return defaultValue;
}
//To reject predefined set of values
function rejectThisValues(value) {
var rejectObj = {
null: true,
undefined: true,
NaN: true,
0: true,
false: true,
"": tsrue
};
return rejectObj[value] ? false : true;
}
//Common Try-Catch function
function applyTryCatch(DATA_OBJ, NAME) {
function tryCatch(myfunction, key) {
return function() {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.error("error in " + key, e);
return false;
}
};
}
for (var key in DATA_OBJ) {
if (typeof DATA_OBJ[key] === "function") {
DATA_OBJ[key] = tryCatch(DATA_OBJ[key], NAME + "." + key);
}
}
}
var main = {
context: undefined,
parseRequestBody: function(body) {
try {
return JSON.parse(body)
} catch (err) {
return false;
}
},
LeadCreate: function(data) {
try {
log.debug('DATA', data);
var RecId = null;
var ConttID = null;
var extras = '';
var contactName = (data.firstname + ' ' + data.lastname);
data.contactName = contactName;
var LeadRecId = main.leadContactCount(data, "customer");
if (LeadRecId) {
if (LeadRecId.isperson == true) {
var company_name = data.company
data.company = main.ContactLeadNaming(company_name, "customer")
var RecId = main.newLeadCreation(data)
} else {
var RecId = LeadRecId.nameID;
// log.debug('RecIdsubmitfiled', RecId)
try {
var submitFieldsPromise = record.submitFields({
type: "customer",
id: RecId,
values: {
leadsource: "2679",
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
} catch (err) {
log.error("ERROR_ submitFieldsPromiseLead", err.message);
}
log.debug('RecIdsubmitfiled', RecId)
}
} else {
var RecId = main.newLeadCreation(data)
}
if (RecId) {
data.RecId = RecId;
var isExist = main.leadContactCount(data, "contact");
log.debug('isExist', isExist)
//log.debug('!!isExist', !isExist)
if (!isExist) {
ConttID = main.newContactCreation(RecId, data);
log.debug('ConttID', ConttID)
}
//Assign the contact Role for the corresponding contact
if (ConttID) {
var submitFieldsPromise = record.submitFields({
type: record.Type.CONTACT,
id: ConttID,
values: {
contactrole: data.contactRole,
},
options: {
enableSourcing: false,
ignoreMandatoryFields: true
}
});
}
if (data.productOfinter) {
var prodt = data.productOfinter;
extras += 'Products of Interest'
for (var key in prodt)
extras += '\n-' + key;
} else
extras.prodt = ""
if (data.message) {
extras += '\n\nAdditional Notes:-\n'
extras += data.message
} else
extras.message = ""
var result = main.CreateUserNote(RecId, (extras), data.contactName)
if (result) {
var results = { status: "SUCCESS", data: 'Succesfully added the contact' };
var strJson = UsrCallback + '(\'' + JSON.stringify(results) +
'\')';
return strJson
} else {
var results = { status: "Error", data: 'Something went wrong' };
var strJson = UsrCallback + '(\'' + JSON.stringify(results) +
'\')';
return strJson
}
} else {
log.error("err@HILE LeadCreate", err)
log.debug("err@HILE search LeadCreate", err)
var result = { status: "Failure", data: 'The company name is already exist' };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
} catch (err) {
log.error("err@HILE LeadCreate", err)
log.debug("err@HILE search options_contactRole", err)
var result = { status: "Error", data: err.message };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
},
newLeadCreation: function(data) {
var objRecord = record.create({
type: record.Type.LEAD,
isDynamic: true
});
objRecord.setValue({
fieldId: 'isperson',
value: "F"
});
try {
objRecord.setValue({
fieldId: 'leadsource',
value: "2679"
});
} catch (err) {
log.error("ERROR_newLeadCreation", err.message);
}
objRecord.setValue({
fieldId: 'custentity_geo_loc',
value: '1'
});
objRecord.setValue({
fieldId: 'companyname',
value: data.company
});
var RecId = objRecord.save();
log.debug('newLeadCreation', RecId);
return RecId
}
//For checking the count of existance for lead or contact
,
leadContactCount: function(data, recType) {
try {
var Filter = [];
var columns = [];
var dataNmID = null;
var isperson = "false"
if (recType == "customer") {
Filter.push(["entityid", "is", data.company]);
Filter.push("AND");
Filter.push(["stage", "anyof", "LEAD", "PROSPECT", "CUSTOMER"]);
columns.push(search.createColumn({ name: "internalid" }))
columns.push(search.createColumn({ name: "isperson" }))
} else if (recType == "contact") {
Filter.push(["entityid", "is", data.contactName]);
Filter.push("AND");
Filter.push(["email", "is", decodeURIComponent(data.email)]);
/* Filter.push("AND");
Filter.push(["company", "is", data.companyname]);*/
}
var leadContactCountSearchObj = search.create({
type: recType,
filters: Filter,
columns: columns
});
var searchResultCount = leadContactCountSearchObj.runPaged().count;
log.debug("leadSearchObj result count", searchResultCount);
if (searchResultCount > 0) {
if (recType == "customer") {
leadContactCountSearchObj.run().each(function(result) {
// .run().each has a limit of 4,000 results
dataNmID = result.getValue(leadContactCountSearchObj.columns[0]);
isperson = result.getValue(leadContactCountSearchObj.columns[1]);
return true;
});
log.debug('recid', { nameID: dataNmID, isperson: isperson })
return { nameID: dataNmID, isperson: isperson }
} else if (recType == "contact") {
return true
}
} else {
log.debug('recid', dataNmID)
return dataNmID
}
} catch (err) {
var result = { status: "Error", data: err.message };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
},
newContactCreation: function(RecId, data) {
var contactReName = main.ContactLeadNaming(data.contactName, "contact")
data.contactName = contactReName;
var ContactRec = record.create({
type: record.Type.CONTACT,
isDynamic: true
});
//log.debug('RecIdif1', RecId);
ContactRec.setValue({
fieldId: 'company',
value: RecId
});
//log.debug('RecIdif2', RecId);
ContactRec.setValue({
fieldId: 'subsidiary',
value: "1"
});
// log.debug('RecIdif3', RecId);
ContactRec.setValue({
fieldId: 'entityid',
value: data.contactName
});
//log.debug('RecIdif4', RecId);
ContactRec.setValue({
fieldId: 'firstname',
value: data.firstname
});
//log.debug('RecIdif5', RecId);
ContactRec.setValue({
fieldId: 'lastname',
value: data.lastname
});
//log.debug('RecIdif6', RecId);
ContactRec.setValue({
fieldId: 'phone',
value: data.phoneno
});
//log.debug('RecIdif7', RecId);
ContactRec.setValue({
fieldId: 'email',
value: decodeURIComponent(data.email)
});
//log.debug('RecIdif8', RecId);
try {
ContactRec.setValue({
fieldId: 'contactrole',
value: data.contactRole
});
} catch (err) {
log.error("ERROR_newContactCreation", err.message);
}
var recordId = ContactRec.save({
enableSourcing: true,
ignoreMandatoryFields: true
});
return recordId
},
ContactLeadNaming: function(name, recType) {
try {
var ContactLeadNamingObj = search.create({
type: recType, //"contact",
filters: [
["entityid", "startswith", name]
],
columns: [
search.createColumn({ name: "entityid" }),
search.createColumn({ name: "email" })
]
});
var searchResultCount = ContactLeadNamingObj.runPaged().count;
var New_name = name;
if (searchResultCount > 0) {
New_name = name + '_' + (searchResultCount + 1)
log.debug('New_name', New_name)
return New_name
} else {
log.debug('New_name', New_name)
return New_name
}
} catch (err) {
var result = { status: "Error", data: err.message };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
},
CreateUserNote: function(leadId, extras, contactName) {
try {
var html_body = " This is a note\n -list1 \n-list2\n\nAdditional Notes:-\n-test note for marshall";
var userNote = record.create({
type: 'note',
isDynamic: true
});
userNote.setValue({
fieldId: 'notetype',
value: 15
});
userNote.setValue({
fieldId: 'entity',
value: leadId
});
userNote.setValue({
fieldId: 'title',
value: "Marshall USA Contact Form" + ' - ' + contactName
});
userNote.setValue({
fieldId: 'direction',
value: "1"
});
userNote.setValue({
fieldId: 'note',
value: extras
});
var NoteId = userNote.save();
return main.formatResponse("SUCCESS", NoteId, null);
} catch (err) {
var result = { status: "Error", data: err.message };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
},
contactRoleSearch: function() {
try {
var estimateSearchObj = search.create({
type: "contactrole",
filters: [
["internalid","anyof","-20","-40","-50","-10","-30"]
],
columns: [
search.createColumn({ name: "name" }),
search.createColumn({ name: "internalid" })
]
});
//return "test";
var options_contactRole = '<option value=" ">Contact Role</option>';
var ObjResult = {}
var Obj = {}
log.error('estimateSearchObj', estimateSearchObj);
var searchResultCount = estimateSearchObj.runPaged().count;
log.error("estimateSearchObj result count", searchResultCount);
estimateSearchObj.run().each(function(result) {
// .run().each has a limit of 4,000 results
Obj = {}
Obj.Id = result.getValue(estimateSearchObj.columns[1]);
Obj.name = result.getValue(estimateSearchObj.columns[0]);
options_contactRole = options_contactRole + '<option value="' + Obj.Id + '">' + Obj.name + '</option>';
// ObjResult.push(Obj)
ObjResult[Obj.Id] = Obj
return true;
});
log.debug('ObjResult', main.formatResponse("SUCCESS", ObjResult, null))
var result = { status: "SUCCESS", data: ObjResult };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson;
} catch (err) {
log.debug("err@HILE search contactRoleSearch", err)
var result = { status: "Error", data: err.message };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
}
},
processRequest: function() {
var requestBody = (this.context.request.parameters);
log.error('requestBody', requestBody);
UsrCallback = requestBody.callback;
if (requestBody.apitype == "do_ContactSearch") {
if (requestBody.GetValue == "contactRoleSearch") {
log.error('requestBodycontact', requestBody.GetValue);
return this.contactRoleSearch(requestBody);
} else if (requestBody.GetValue == "createLead") {
log.error('requestBodysgsfg', requestBody.data);
return this.LeadCreate(main.parseRequestBody(requestBody.data));
}
} else {
log.debug('data', "bad request")
}
var result = { status: "Error", data: 'ERROR WHILE PARSING JSON' };
var strJson = UsrCallback + '(\'' + JSON.stringify(result) +
'\')';
return strJson
},
onRequest: function(context) {
this.context = context;
log.error(' this.context', this.context)
if (context.request.method === "GET") {
context.response.write(main.processRequest());
}
return true;
},
formatResponse: function(SHORT_RESPONSE, LONG_RESPONSE, FAULT_POSITION, MORE_INFO) {
var responseObj = {};
responseObj.response = (SHORT_RESPONSE) ? SHORT_RESPONSE : "FAILURE";
responseObj.message = (LONG_RESPONSE) ? LONG_RESPONSE : null;
responseObj.position = (FAULT_POSITION) ? FAULT_POSITION : null;
responseObj.information = (MORE_INFO) ? MORE_INFO : null;
return JSON.stringify(responseObj);
}
}
applyTryCatch(main, "main");
return main;
});
if (!Array.prototype.filter) {
Array.prototype.filter = function(func, thisArg) {
'use strict';
if (!((typeof func === 'Function' || typeof func === 'function') && this))
throw new TypeError();
var len = this.length >>> 0,
res = new Array(len),
t = this,
c = 0,
i = -1;
if (thisArg === undefined) {
while (++i !== len) {
if (i in this) {
if (func(t[i], i, t)) {
res[c++] = t[i];
}
}
}
} else {
while (++i !== len) {
if (i in this) {
if (func.call(thisArg, t[i], i, t)) {
res[c++] = t[i];
}
}
}
}
res.length = c;
return res;
};
}
IFrame
<!-- ifram contact:html -->
<p>
<style>
.NSiframe {
width: 100%;
min-height: 965px;
}
@media only screen and (max-height: 1366px) {
.NSiframe {
min-height: 965px;
}
}
@media only screen and (max-height: 1024px) {
.NSiframe {
min-height: 1215px;
}
}
@media only screen and (max-height: 812px) {
.NSiframe {
min-height: 1255px;
}
}
@media only screen and (max-height: 441px) {
.NSiframe {
min-height: 1260px;
}
}
@media only screen and (min-width: 1200px) {
.NSiframe {
min-height: 952px;
}
}
</style> <iframe class="NSiframe" src="corresponding HTML Page link" width="100%" style="border: 0;" frameborder="0" scrolling="no"></iframe>
</p>
<!-- /ifram contact -->
<!-- ifram contactparagraph -->
<p> </p>
<!-- /ifram contact -->