Jira Code: PAL-5, 6
This form creates a lead in NetSuite on submit, the form will check for the duplicate record, if any duplicate exists a script will be run to edit/replace the comment with the new one.
<nlform>
<!DOCTYPE html>
<html>
<head>
<title>
Contact Us
</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.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>
</head>
<body>
<div style="display: none;">
<nlsubsidiary>
<nlfirstname>
<nllastname>
<nlphone>
<nlemail>
<nlcomments>
<nlcustomform>
</nlcustomform>
</nlcomments>
</nlemail>
</nlphone>
</nllastname>
</nlfirstname>
</nlsubsidiary>
</div>
<div class="container">
<form class="needs-validation" novalidate>
<div class="form-row mt-5">
<div class="col-sm-12 col-12 col-md-12 col-lg-12 mb-2">
<label class="font-weight-bold text-dark">Your Name<sup class="font-weight-bold text-danger">*</sup></label>
</div>
<div class="col-sm-6 col-md-6 col-lg-6 col-6 mb-3">
<input type="text" class="form-control" id="firstname1" placeholder="First name" required="">
<div class="valid-feedback">
Looks good!
</div>
</div>
<div class="col-sm-6 col-md-6 col-lg-6 col-6 mb-3">
<input type="text" class="form-control" id="lastname1" placeholder="Last name" required="">
<div class="valid-feedback">
Looks good!
</div>
</div>
<div class="col-sm-12 col-12 col-md-12 col-lg-12 mb-3 form-group">
<label class="font-weight-bold text-dark">Email<sup class="font-weight-bold text-danger">*</sup></label>
<input type="email" class="form-control" id="email1" aria-describedby="emailHelp" placeholder="Enter email" pattern="^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$" required="">
<div class="valid-feedback">
Looks good!
</div>
</div>
<div class="col-sm-12 col-12 col-md-12 col-lg-12 mb-3 form-group">
<label class="font-weight-bold text-dark">Phone<sup class="font-weight-bold text-danger">*</sup></label>
<input type="tel" class="form-control" id="phone1" aria-describedby="telephoneHelp" placeholder="###-###-####" pattern="^\+{0,2}([\-\. ])?(\(?\d{0,3}\))?([\-\. ])?\(?\d{0,3}\)?([\-\. ])?\d{3}([\-\. ])?\d{4}" required="">
<div class="valid-feedback">
Looks good!
</div>
<div class="invalid-feedback">
Invalid Number! (ex:000-000-0000)
</div>
</div>
<div class="col-sm-12 col-12 col-md-12 col-lg-12 mb-2 mt-3">
<div class="form-group">
<label class="font-weight-bold text-dark" for="exampleFormControlTextarea1">Tell us a little about your project.</label>
<textarea class="form-control" id="comments1" rows="3"></textarea>
</div>
</div>
</div>
<div class="mb-5 col-sm-12 col-12 col-md-12 col-lg-12 text-center">
<button class="btn btn btn-dark btn-lg" id="sumbitBtn" type="submit" style="display: none;">Send</button>
<button class="btn btn btn-dark btn-lg" id="duplicateBtn" type="button">Send</button>
</div>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
$(function() {
$('#duplicateBtn').click(function() {
var allfilled = true;
var mandatoryFields = ['firstname1', 'lastname1', 'email1', 'phone1'];
mandatoryFields.forEach(function(keyID) {
if ($('#' + keyID).val().trim() == '') {
var value2 = $('#' + keyID).val().trim();
$('#' + keyID).val(value2);
allfilled = false;
} else {
var fieldid = keyID.replace(/1/g, '');
var value = $('#' + keyID).val().trim();
$('#' + fieldid).val(value);
}
});
var emailid = $('#email1').val().trim();
var firstname1 = $('#firstname1').val().trim();
var lastname1 = $('#lastname1').val().trim();
var phone1 = $('#phone1').val().trim();
var comment = $('#comments1').val().trim();
if (comment != '')
$('#comments').val(comment);
var u = "https://forms.na3.netsuite.com/app/site/hosting/scriptlet.nl?script=291&deploy=1&compid=5102952&h=92a561884d3fe2221b9a&email=" + emailid + "&comment=" + comment+ "&firstname1=" + firstname1+ "&lastname1=" + lastname1+ "&phone1=" + phone1;
cb = 'myCallBackSaveContactForm';
getJSONP(u + '&callback=' + cb);
});
});
function myCallBackSaveContactForm(data) {
console.log("data", data)
var myObj = JSON.parse(data);
var emailid = $('#email').val().trim();
if (myObj == 'ALREADY_EXISTS') {
window.top.location.href = 'https://www.palmettopublishinggroup.com/confirmation';
} else if (myObj == 'ERROR') {
$('#sumbitBtn').click();
} else {
$('#sumbitBtn').click();
window.top.location.href = 'https://www.palmettopublishinggroup.com/confirmation';
}
}
function getJSONP(url) {
var script = document.createElement('script');
var head = document.getElementsByTagName('head')[0] || document.documentElement;
script.src = url
head.appendChild(script);
}
</script>
</div>
</body>
</html>
</nlform>
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/**
* Script Description
* This suitelet to search customer.
*/
/*******************************************************************************
*
*
* NetSuite Name :PAL-5 JJ SL Duplicate Check
* Script ID: customscript_jj_customer_search
*
* *****************************************************************************
*
*
* $Author: Jobin & Jismi IT Services LLP $
*
* DESCRIPTION
* Suitelet to search customer to find the duplicate.
*
* Date Created :11-05-2019
*
* REVISION HISTORY Update:
*
*
*
******************************************************************************/
var CONTEXT;
var CALL_BACK;
define(['N/file', 'N/search', 'N/runtime', 'N/record', 'N/https', 'N/encode', 'N/ui/serverWidget', 'N/email'],
function (file, search, runtime, record, https, encode, serverWidget, email) {
var main = {
onRequest: function (context) {
var phoneValidation=/^\+{0,2}([\-\. ])?(\(?\d{0,3}\))?([\-\. ])?\(?\d{0,3}\)?([\-\. ])?\d{3}([\-\. ])?\d{4}/;
var emailValidation=/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
CONTEXT=context;
var email = context.request.parameters.email;
var firstname1 = context.request.parameters.firstname1;
var lastname1 = context.request.parameters.lastname1;
var phone1 = context.request.parameters.phone1;
var comment = context.request.parameters.comment;
var callBackFuncStr = context.request.parameters.callback;
CALL_BACK=callBackFuncStr;
if(email==''||firstname1==''||lastname1==''||phone1=='')
{
var strJson = callBackFuncStr + '(\'' + JSON.stringify('ERROR') + '\')';
context.response.write(strJson);
}
else if(!phoneValidation.test(phone1) || !emailValidation.test(email))
{
var strJson = callBackFuncStr + '(\'' + JSON.stringify('ERROR') + '\')';
context.response.write(strJson);
}
else
{
var customerSearchObj = search.create({
type: "customer",
filters: [
["email", "is", email]
],
columns: [
search.createColumn({
name: "entityid",
sort: search.Sort.ASC,
label: "Name"
}),
search.createColumn({
name: "email",
label: "Email"
}),
search.createColumn({
name: "phone",
label: "Phone"
}),
search.createColumn({
name: "internalid",
label: "Internal ID"
})
]
});
var found = customerSearchObj.runPaged().count > 0 ? true : false;
log.debug(found)
if (found) {
var resultsearch = customerSearchObj.run().getRange(0, 1);
var idcustomer = resultsearch[0].getValue({
name: "internalid",
label: "Internal ID"
});
var rec = record.load({
type: record.Type.CUSTOMER,
id: idcustomer,
isDynamic: false
});
rec.setValue({
fieldId: 'comments',
value: comment
});
rec.save();
}
if (found) {
var strJson = callBackFuncStr + '(\'' + JSON.stringify('ALREADY_EXISTS') + '\')';
context.response.write(strJson);
} else {
var strJson = callBackFuncStr + '(\'' + JSON.stringify('ALREADY_NOT_EXISTS') + '\')';
context.response.write(strJson);
}
}
}
}
for (var key in main) {
if (typeof main[key] === 'function') {
main[key] = trycatch(main[key], key);
}
}
function trycatch(myfunction, key) {
return function () {
try {
return myfunction.apply(this, arguments);
} catch (e) {
log.debug("e in " + key, e);
var strJson = CALL_BACK + '(\'' + JSON.stringify('ERROR') + '\')';
CONTEXT.response.write(strJson);
}
}
};
return main;
});