Jira Code: TM-162
Portlet script for directly creating the lead record, the contact first name and last name can also enter via this portlet. This will create a new contact record which attached to this lead record.
/**
* @NApiVersion 2.x
* @NScriptType Portlet
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Take5 Media
* TM-162
* Add Quick add lead
*************************************************************************
* Date : 14-01-2019
*
* Author:Peter Ward
* Script Description :
* Date created : 14-01-2019
*Add LContact First Name and last name
* REVISION HISTORY
*
* Revision 1.0 ${14-01-2019} nd :marg created
*
*
*
******************************************************************************/
define(['N/record', 'N/ui/serverWidget', 'N/url', 'N/runtime' ],
function(record, serverWidget, url, runtime) {
/**
* Definition of the Portlet script trigger point.
*
* @param {Object} params
* @param {Portlet} params.portlet - The portlet object used for rendering
* @param {number} params.column - Specifies whether portlet is placed in left (1), center (2) or right (3) column of the dashboard
* @param {string} params.entity - (For custom portlets only) references the customer ID for the selected customer
* @Since 2015.2
*/
function render(params) {
try{
var portlet = params.portlet;
portlet.title = 'QUICK ADD-LEADS';
portlet.clientScriptFileId = '1089';
portlet.setSubmitButton({
url: 'www',
label: 'Save'
});
var leadId = portlet.addField({
id : 'textfield_leadid',
type : serverWidget.FieldType.TEXT,
label : 'LEAD ID'
});
leadId.isMandatory = true;
var firstname = portlet.addField({
id : 'textfield_firstname',
type : serverWidget.FieldType.TEXT,
label : 'First Name'
});
firstname.isMandatory = true;
var middlename = portlet.addField({
id : 'textfield_middlename',
type : serverWidget.FieldType.TEXT,
label : 'Middle Name'
});
middlename.isMandatory = true;
var lastname = portlet.addField({
id : 'textfield_lastname',
type : serverWidget.FieldType.TEXT,
label : 'Last Name'
});
lastname.isMandatory = true;
var companyName = portlet.addField({
id : 'textfield_companyname',
type : serverWidget.FieldType.TEXT,
label : 'COMPANY NAME'
});
companyName.isMandatory = true;
var webAddress = portlet.addField({
id : 'textfield_webaddress',
type : serverWidget.FieldType.TEXT,
label : 'WEB ADDRESS'
});
webAddress.isMandatory = true;
var email = portlet.addField({
id : 'textfield_email',
type : serverWidget.FieldType.TEXT,
label : 'EMAIL'
});
var phone = portlet.addField({
id : 'textfield_phone',
type : serverWidget.FieldType.TEXT,
label : 'PHONE'
});
var category = portlet.addField({
id : 'textfield_category',
type : serverWidget.FieldType.TEXT,
label : 'Category'
});
category.updateDisplayType({
displayType: serverWidget.FieldDisplayType.HIDDEN
});
var leadsource = portlet.addField({
id : 'textfield_leadsource',
type : serverWidget.FieldType.SELECT,
label : 'LEAD SOURCE'
});
leadsource.addSelectOption({
value: '-2',
text: 'Ad'
});
leadsource.addSelectOption({
value: '50854',
text: 'Buyer Zone'
});
leadsource.addSelectOption({
value: '50860',
text: 'Inbound Blogs'
});
leadsource.addSelectOption({
value: '50859',
text: 'Inbound Website'
});
leadsource.addSelectOption({
value: '50856',
text: 'LinkedIn Inbound'
});
leadsource.addSelectOption({
value: '50855',
text: 'LinkedIn Self'
});
leadsource.addSelectOption({
value: '50858',
text: 'Next Mark'
});
leadsource.addSelectOption({
value: '-3',
text: 'Other'
});
leadsource.addSelectOption({
value: '-4',
text: 'Partner Referral'
});
leadsource.addSelectOption({
value: '-5',
text: 'Trade Show'
});
leadsource.addSelectOption({
value: '-6',
text: 'Web'
});
leadsource.addSelectOption({
value: '50857',
text: 'Web Leads'
});
leadsource.defaultValue = 1;
leadsource.isMandatory = true;
// var leadRec = record.create({
// type: "LEAD",
// isDynamic: true
// });
// log.debug('leadRec',leadRec)
// leadRec.setValue({
// fieldId: 'entityid',
// value: context.request.parameters.textfield_leadid
// });
// leadRec.setValue({
// fieldId: 'companyname',
// value: context.request.parameters.textfield_companyname
// });
// leadRec.setValue({
// fieldId: 'url',
// value: context.request.parameters.textfield_webaddress
// });
// leadRec.setValue({
// fieldId: 'email',
// value: context.request.parameters.textfield_email
// });
// leadRec.setValue({
// fieldId: ' phone',
// value: context.request.parameters.textfield_phone
// });
// leadRec.setValue({
// fieldId: 'leadsource',
// value: context.request.parameters.textfield_leadsource
// });
// /*leadRec.setValue({
// fieldId: 'firstname',
// value: context.request.parameters.textfield_firstname
// });
// leadRec.setValue({
// fieldId: 'middlename',
// value: context.request.parameters.textfield_middlename
// });
// leadRec.setValue({
// fieldId: 'lastname',
// value: context.request.parameters.textfield_lastname
// });*/
// leadRec.save();
} catch (e) {
log.debug({
title : 'form for lead',
details : e.message
});
}
}
return {
render: render
};
});
CS
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Take5 Media
* TM-162
* Add Quick add lead
*************************************************************************
* Date : 14-01-2019
*
* Author:Peter Ward
* Script Description :
* Date created : 14-01-2019
*Add LContact First Name and last name
* REVISION HISTORY
*
* Revision 1.0 ${14-01-2019} nd : created
*
*
*
******************************************************************************/
define(['N/record','N/search','N/currentRecord'],
function(record,search,currentRecord) {
function saveRecord(scriptContext) {
var records = scriptContext.currentRecord;
// var leadRec = record.create({
// type: "LEAD",
// isDynamic: true
// });
// log.debug('leadRec',leadRec)
var entity = records.getValue({
fieldId: 'textfield_leadid',
});
console.log('entity',entity)
var companyname = records.getValue({
fieldId: 'textfield_companyname',
});
console.log('companyname',companyname)
var webaddress = records.getValue({
fieldId: 'textfield_webaddress',
});
var email = records.getValue({
fieldId: 'textfield_email',
});
var phone = records.getValue({
fieldId: 'textfield_phone',
});
var leadsource = records.getValue({
fieldId: 'textfield_leadsource',
});
console.log('leadsource',leadsource)
var firstname = records.getValue({
fieldId: 'textfield_firstname',
});
var middlename = records.getValue({
fieldId: 'textfield_middlename',
});
var lastname = records.getValue({
fieldId: 'textfield_lastname',
});
if(entity && lastname && middlename && firstname && companyname && webaddress && leadsource ){
var leadRec = record.create({
type: "LEAD"
});
log.debug('leadRec',leadRec)
leadRec.setValue({
fieldId: 'entityid',
value: entity
});
console.log('entity1',entity)
leadRec.setValue({
fieldId: 'companyname',
value: companyname
});
leadRec.setValue({
fieldId: 'url',
value: webaddress
});
leadRec.setValue({
fieldId: 'email',
value: email
});
leadRec.setValue({
fieldId: 'phone',
value: phone
});
leadRec.setValue({
fieldId: 'category',
value: 4
});
leadRec.setValue({
fieldId: 'leadsource',
value: leadsource
});
var internalid = leadRec.save();
alert("You have successfully created the lead record")
var leadcontact = record.create({
type: "CONTACT"
});
// leadcontact.setValue({
// fieldId: 'entityid',
// value: internalid
// });
leadcontact.setText({
fieldId: 'company',
text: entity
});
leadcontact.setValue({
fieldId: 'firstname',
value: firstname
});
leadcontact.setValue({
fieldId: 'middlename',
value: middlename
});
leadcontact.setValue({
fieldId: 'lastname',
value: lastname
});
var contactid = leadcontact.save();
console.log('contactid',contactid)
window.location.reload();
}
else{
alert("please fill all mandatory fields")
}
}
return {
saveRecord: saveRecord
};
});