Jira code: MBS 11, MBS 12
Client needs a custom Page to display the Transaction search details. User may filter the results using Start Date, End Date and the Amount field.
On the consensus form, the user will select any number of rows from the List and click one of the Print button. The print button will create one PDF file and print it on the screen.
Suitelet
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Moneta Business Solutions MBS -11 Create a SL for showing results
* of SS "BA-BS Formu" ID:46
* ************************************************************************ Date :
* 08/02/2019
*
* Author: Jobin & Jismi IT Services LLP Script Description : This is to Create
* a SL for showing results of SS "BA-BS Formu" ID:46 Date created : 08/02/2019
*
* REVISION HISTORY
*
* Revision 1.0 ${08/02/2019} aj : created
*
*
******************************************************************************/
define(
[ 'N/record', 'N/search', 'N/ui/serverWidget','N/render' ,'N/email','N/file','N/encode','N/task'],
/**
* @param {record}
* record
* @param {search}
* search
* @param {serverWidget}
* serverWidget
*/
function(record, search, serverWidget,render,email,file,encode,task) {
/**
* Definition of the Suitelet script trigger point.
*
* @param {Object}
* context
* @param {ServerRequest}
* context.request - Encapsulation of the incoming
* request
* @param {ServerResponse}
* context.response - Encapsulation of the Suitelet
* response
* @Since 2015.2
*/
function onRequest(context) {
try {
var pageIndex = assignDefaultValue(
context.request.parameters.pageindexfield, 0);
var startDateSelected = context.request.parameters.startDateSelected;
var endDateSelected = context.request.parameters.endDateSelected;
var amountSelected = context.request.parameters.amountSelected;
var mode =context.request.parameters.mode;
var returnObj = context.request.parameters.returnObj;
if (context.request.method === 'GET' ) {
// to create a form
var form = serverWidget.createForm({
title : 'BA-BS Formu'
});
// start date
var startDate = form.addField({
id : 'custpage_start_date',
label : 'Start Date',
type : serverWidget.FieldType.DATE
});
if (checkForParameter(startDateSelected))
startDate.defaultValue = startDateSelected;
// end date
var endDate = form.addField({
id : 'custpage_end_date',
label : 'End Date',
type : serverWidget.FieldType.DATE
});
if (checkForParameter(endDateSelected))
endDate.defaultValue = endDateSelected;
// Amount
var amount = form.addField({
id : 'custpage_amount',
label : 'Amount',
type : serverWidget.FieldType.CURRENCY
});
if (checkForParameter(amountSelected))
amount.defaultValue = amountSelected;
// Sublist
var searchSublist = form.addSublist({
id : 'custpage_search_sublist',
type : serverWidget.SublistType.LIST,
label : 'BA-BS Mutabakat Listesi'
});
// to add buttons
var display = form.addButton({
id : 'custpage_display',
label : 'Display',
functionName : 'displayResult'
});
var print = form.addButton({
id : 'custpage_print',
label : 'Print',
functionName : 'printData'
});
var sendMail = form.addButton({
id : 'custpage_send_mail',
label : 'Send E-mail',
functionName : 'sendMailTo'
});
var pageIndexField = form.addField({
id : 'pageindexfield',
type : serverWidget.FieldType.SELECT,
label : 'Page Index'
}).updateLayoutType({
layoutType : serverWidget.FieldLayoutType.STARTROW
});
pageIndexField.defaultValue = pageIndex;
var runSearchObj = runSearch(
startDateSelected, endDateSelected, amountSelected,pageIndexField, pageIndex);
if (checkForParameter(runSearchObj)) {
// dynamically define the column list based on the saved
var select = searchSublist.addField({
id : 'custpage_select',
label : 'Yazdir',
type : serverWidget.FieldType.CHECKBOX
});
searchSublist.addMarkAllButtons();
// search definition
var columns = runSearchObj.columns;
for ( var key in columns) {
if (columns[key].label != 'nodisplay') {
searchSublist.addField({
id : key,
label : columns[key].label,
type : serverWidget.FieldType.TEXT
});
}
}
var fieldValue;
runSearchObj.result
.forEach(function(eachRow, index) {
for ( var key in columns) {
if (columns[key].label != 'nodisplay') {
fieldValue = (eachRow
.getText(columns[key])) ? eachRow
.getText(columns[key])
: eachRow
.getValue(columns[key]);
searchSublist.setSublistValue({
id : key,
value : assignDefaultValue(
fieldValue, " - "),
line : index
});
}
}
});
}
form.clientScriptFileId = 4516;
if(mode=='download')
{
returnObj = JSON.parse(returnObj);
// to get the each files
//to get PDF set
var XML = getPDFContents(returnObj);
var jsonFileDownload=file.create({
name:'JsonFileDownload.txt',
fileType:file.Type.PLAINTEXT,
contents:XML,
folder:1214
});
jsonFileDownload.save();
var renderer = render.create();
renderer.templateContent =XML
var pdfFile =renderer.renderAsPdf();
context.response.writeFile(pdfFile, true);
}
else if(mode=='send')
{
var scheduleScrptTask = task.create({
taskType: task.TaskType.SCHEDULED_SCRIPT,
scriptId: 'customscript_mbs13_jj_ss_sendmail',
deploymentId:'customdeploy_mbs13_jj_ss_sendmail',
params: {custscript_object:returnObj}
});
scheduleScrptTask.submit();
//context.response.write("Initiated mail send ....");
context.response.writePage(form);
}
else
{
context.response.writePage(form);
}
}
// 4516
} catch (e) {
log.debug("Err@ FN onRequest", e);
log.error("Err@ onAction FN ",e.message);
}
}
/****************************************************
* Function to get XML Contents
****************************************************/
function getPDFContents(returnObj)
{
try{
var XML = '<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd"> <pdfset>';
// to loop the contents
for(var key in returnObj)
{
XML = XML+'<pdf>'+
' <head>'+
' <style>'+
' .normalParagraph{'+
' '+
' font-size: 16px;'+
' }'+
' .boldParagraph{'+
' font-weight: bold;'+
' font-size: 16px;'+
' }'+
' table, th, td {'+
' border: 1px solid #6f6d6d;'+
' border-collapse: collapse;'+
'}'+
' .with-no-border{'+
' border:0px;'+
' border-collapse: collapse;'+
' }'+
' </style>'+
' <macrolist>'+
' <macro id="nlheader">'+
' '+
'<table class="with-no-border" data-page="1" data-table="1" border="0" style="align:left" width="100%" height="30%">'+
' <tr class="with-no-border" ><td class="with-no-border" colspan="2" style="font-weight: bold;font-size: 18px;font-style:italic" >'+
' Ba Bs<br />MutakabatMektubu'+
' '+
' </td>'+
' '+
' '+
' <td class="with-no-border" >'+
' <img src="https://system.eu2.netsuite.com/core/media/media.nl?id=2424&c=4977528&h=8b9a72108b24a8eea071" />'+
' '+
' </td> </tr>'+
' <tr class="with-no-border" >'+
' <td class="with-no-border" >'+
' <p style="font-size: 16px;"> Tarih: '+returnObj[key].stringDate+'</p>'+
' </td>'+
' </tr>'+
'</table>'+
' </macro>'+
' </macrolist>'+
' </head>'+
' <body header="nlheader" header-height="13.5%" >'+
' '+
' <p class="boldParagraph"> Konu : 213 Sayılı VUK'un 362 Sıra Nolu Genel Tebliği Kapsamında Bildirilmesi Gereken Form Ba ve Form BsMutabakatı Hk;</p>'+
' <p class="normalParagraph">Firma Unvanı:'+escape_for_xml(key)+'</p>'+
' '+
' <p class="normalParagraph"> <b>Ekim</b> ayına ait Ba ve Bs formlarında karşılıklı mutabakatın sağlanması açısından firmanıza ait Alış ve Satışlarınıza ilişkinform bilgilerimiz aşağıda sunulmuştur. Konu ile ilgili durumunuzu bu mektubun alt kısmını onaylayarak tarafımıza faksgönderilmesini, eğer mutabık değilseniz Firmanız kayıtlarında gözüken fatura adedini ve faturaların toplam tutarını yazaraktarafımıza en kısa sürede göndermenizi rica ederiz.</p> '+
' <p class="normalParagraph">Saygılarımızla,</p>'+
' '+
' <p class="normalParagraph">Kaşe İmza</p> '+
' '+
' <p><strong>Ba (Mal veya Hizmet Alımı) Formu Bilgilerimiz :</strong></p>'+
' <table style="border-style: solid;">'+
' <tr>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Soyadı/Adı veya Unvanı'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Vergi/T.C. Kimlik No'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Belge Adedi'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Toplam Bedeli (KDVHariç)'+
' </td>'+
' </tr>'+
' <tr >'+
' <td>'+
escape_for_xml(key)+
' </td>'+
' <td>'+
returnObj[key].taxAdmin+
' </td>'+
' <td>'+
returnObj[key].baDocCount+
' </td>'+
' <td>'+
returnObj[key].baAmount+
' </td>'+
' </tr>'+
' '+
' </table>'+
' '+
' '+
' <p><strong>Bs (Mal veya Hizmet Satış) Formu Bilgilerimiz :</strong></p>'+
' <table style="border-style: solid;">'+
' <tr>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Soyadı/Adı veya Unvanı'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Vergi/T.C. Kimlik No'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Belge Adedi'+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Toplam Bedeli (KDVHariç)'+
' </td>'+
' </tr>'+
' <tr >'+
' <td>'+
escape_for_xml(key)+
' </td>'+
' <td>'+
returnObj[key].taxAdmin+
' </td>'+
' <td>'+
returnObj[key].bsDocCount+
' </td>'+
' <td>'+
returnObj[key].bsAmount+
' </td>'+
' </tr>'+
' '+
' </table>'+
' '+
' <p>'+
' <br />'+
' </p>'+
' <table style="border-style: solid;">'+
' <tr>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Mutabıkız '+
' </td>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' '+
' </td>'+
' </tr>'+
' <tr>'+
' <td style="font-weight: bold;font-size: 16px;">'+
' Mutabık Değiliz'+
' </td>'+
' '+
' <td style="font-weight: bold;font-size: 16px;">'+
' '+
' </td>'+
' </tr>'+
' '+
' '+
' </table>'+
' <br />'+
' <p class="boldParagraph"> Firma Kaşe-İmza</p>'+
''+
' '+
' </body>'+
' </pdf>';
}
XML=XML+'</pdfset>'
return XML;
}catch(e)
{
log.debug("Err@ FN getPDFContents",e);
log.error("Err@ onAction FN ",e.message);
}
}
/*******************************************************************
* To format the search according to page Index
******************************************************************/
function formatSavedSearch(savedSearchObj, pageIndexField,
pageIndex) {
try {
var columns = savedSearchObj.columns;
var columnsData = {};
columns.forEach(function(result, counter) {
// columnsData['custpage_col_' + counter] = result;
columnsData[(columnsData[result.name]) ? (result.name
+ '_' + counter) : (result.name)] = result;
});
// Paginating Results
var searchPageRanges,size =15;;
if(savedSearchObj.length<15)
{
size=savedSearchObj.length;
}
try {
searchPageRanges = savedSearchObj.runPaged({
pageSize : size
});
} catch (err) {
return {
status : true,
columns : columnsData,
result : []
};
}
if (searchPageRanges.pageRanges.length < 1)
return {
status : true,
columns : columnsData,
result : []
};
for (var i = 0, j = searchPageRanges.pageRanges.length; i < j; i++) {
pageIndexField.addSelectOption({
value : i,
text : i + 1 + ' of ' + j + ' Pages'
});
}
// Fetching Row Data
var rowData = [];
searchPageRanges.fetch({
index : pageIndex
}).data.forEach(function(result) {
rowData.push(result);
});
return {
status : true,
columns : columnsData,
result : rowData
};
} catch (e) {
log.debug("Err@ FN formatSavedSearch", e.message);
log.error("Err@ onAction FN ",e.message);
}
}
/*******************************************************************
* To Create Search
*
******************************************************************/
function runSearch(startDateSelected,
endDateSelected, amountSelected,pageIndexField, pageIndex) {
try {
var filterArray = [
[ "mainline", "is", "T" ],
"AND",
[ "status", "anyof", "VendBill:A", "CustCred:A",
"CustInvc:A" ] ];
var isFirstElement = 0;
if (checkForParameter(startDateSelected)
&& checkForParameter(endDateSelected)) {
filterArray.push("AND", [ "trandate", "within",
startDateSelected, endDateSelected ]);
} else if (checkForParameter(endDateSelected)) {
filterArray.push("AND", [ "trandate", "onorbefore",
endDateSelected ]);
} else if (checkForParameter(startDateSelected)) {
filterArray.push("AND", [ "trandate", "onorafter",
startDateSelected ]);
}
if (checkForParameter(amountSelected)) {
filterArray.push(
"AND",
[["sum(formulacurrency: case when ({type} = 'Bill' OR {type} = 'Invoice') Then {netamountnotax} Else 0 End)","greaterthanorequalto",amountSelected],"OR",["sum(formulacurrency: case when ({type} = 'Bill' ) Then {netamountnotax} Else 0 End)","greaterthanorequalto",amountSelected],"OR",["sum(formulacurrency: case when ( {type} = 'Invoice') Then {netamountnotax} Else 0 End)","greaterthanorequalto",amountSelected]]);
}
// to create search
var transactionSearchObj = search
.create({
type : "transaction",
filters : filterArray,
columns : [
search.createColumn({
name : "entity",
summary : "GROUP",
label : "Unvan"
}),
search
.createColumn({
name : "formulatext",
summary : "GROUP",
formula : "case when {vendor.custentity_vergi_dairesi} IS NOT NULL Then {vendor.custentity_vergi_dairesi} ELSE case when {customermain.custentity_vergi_dairesi} IS NOT NULL Then {customermain.custentity_vergi_dairesi} ELSE 'Boş' END END ",
label : "Vergi Dairesi"
}),
search
.createColumn({
name : "formulatext",
summary : "GROUP",
formula : "case when {vendor.custentity_vergi_no} IS NOT NULL Then {vendor.custentity_vergi_no} ELSE case when {customermain.custentity_vergi_no} IS NOT NULL Then {customermain.custentity_vergi_no} ELSE 'Boş' END END",
label : "Vergi No"
}),
search
.createColumn({
name : "formulanumeric",
summary : "SUM",
formula : "case when {type} = 'Bill' Then 1 Else 0 End",
label : "BA - Belge Sayısı"
}),
search
.createColumn({
name : "formulacurrency",
summary : "SUM",
formula : "case when {type} = 'Bill' Then {netamountnotax} Else 0 End",
label : "BA - Toplam Bedel (KDV Hariç)"
}),
search
.createColumn({
name : "formulanumeric",
summary : "SUM",
formula : "case when {type} = 'Invoice' Then 1 Else 0 End",
label : "BS - Belge Sayısı"
}),
search
.createColumn({
name : "formulacurrency",
summary : "SUM",
formula : "case when {type} = 'Invoice' Then {netamountnotax} Else 0 End",
label : "BS - Toplam Bedel (KDV Hariç)"
}),
search
.createColumn({
name : "formulatext",
summary : "GROUP",
formula : "case when {vendor.email} IS NOT NULL Then {vendor.email} ELSE case when {customermain.email} IS NOT NULL Then {customermain.email} ELSE 'Boş' END END",
label : "E-mail"
}),
search
.createColumn({
name : "formulatext",
summary : "GROUP",
formula : "case when {vendor.phone} IS NOT NULL Then {vendor.phone} ELSE case when {customermain.phone} IS NOT NULL Then {customermain.phone} ELSE 'Boş' END END",
label : "Telefon"
}) ]
});
var searchResultCount = transactionSearchObj.runPaged().count;
return formatSavedSearch(transactionSearchObj,
pageIndexField, pageIndex);
// }
} catch (e) {
log.error("Err@ FN runSearch", e);
}
}
/*******************************************************************
* To check whether a value exists in parameter
******************************************************************/
function checkForParameter(parameter, parameterName) {
try {
if (parameter !== null && parameter !== undefined
&& parameter !== false && parameter !== "null"
&& parameter !== "undefined"
&& parameter !== "false" && parameter != ""
&& parameter != " ") {
return true;
} else {
if (parameterName)
log.debug('Empty Value found',
'Empty Value for parameter '
+ parameterName);
return false;
}
} catch (e) {
log.error("Err@ FN checkForParameter", e);
}
}
/*******************************************************************
* To assign a default value if the it is empty
*
* @param value
* @param defaultValue
* @returns
******************************************************************/
function assignDefaultValue(value, defaultValue) {
try {
if (checkForParameter(value))
return value;
else
return defaultValue;
} catch (e) {
log.error("Err@ FN assignDefaultValue", e);
}
}
/*******************************************************************
* Fix text
*
* @param argument
* @returns Created By JJ on 15-Nov-2017 4:30:21 PM
*/
function escape_for_xml(argument, xml) {
try {
if (argument != "" && argument != null) {
//var newString = xml.escape({
// xmlText : argument
//});
argument = argument.replace(/&/g, '&');
argument = argument.replace(/</g, '<');
argument = argument.replace(/>/g, '>');
argument = argument.replace(/"/g, '"');
argument = argument.replace(/'/g, ''');
return argument;
} else {
return "";
}
} catch (e) {
log.error({
title : e.name,
details : e.message
});
}
}
return {
onRequest : onRequest
};
});
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Moneta Business Solutions
* MBS -11 Create a SL for showing results of SS "BA-BS Formu" ID:46
*************************************************************************
* Date : 08/02/2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This is to Create a SL for showing results of SS "BA-BS Formu" ID:46
* Date created : 08/02/2019
*
* REVISION HISTORY
*
* Revision 1.0 ${08/02/2019} aj : created
*
*
******************************************************************************/
define(
[ 'N/record', 'N/search', 'N/ui/dialog', 'N/ui/message', 'N/url','N/https', 'N/currentRecord' ],
/**
* @param {record} record
* @param {search} search
* @param {dialog} dialog
* @param {message} message
*/
function(record, search, dialog, message,url,https,currentRecord) {
/**
* Function to be executed after page is initialized.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
*
* @since 2015.2
*/
function pageInit(scriptContext) {
try{
//avoid the standard NetSuite warning message when navigating away
if (window.onbeforeunload) {
window.onbeforeunload = function() {
null;
};
}
}catch(e)
{
console.log("Err@ FN pageInit=",e.message);
}
}
/***************************
* function to download
*/
function printData()
{
try{
// to get the total line num
// to get the total line num
var currRecord = currentRecord.get();
var lineNum = currRecord.getLineCount({
sublistId:'custpage_search_sublist'
});
var returnObj={};
var selected=0;
// to get selected lines
for(var i=0;i<lineNum;i++)
{
var isSelected = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'custpage_select',
line:i
});
if(isSelected==true)
{
selected++;
// get email
var email = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulatext_7',
line:i
});
var taxAdmin = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulatext_2',
line:i
});
//formulanumeric
var baDocCount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulanumeric',
line:i
});
var bsDocCount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulanumeric_5',
line:i
});
var baAmount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulacurrency',
line:i
});
var bsAmount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulacurrency_6',
line:i
});
var name = currRecord.getSublistText({
sublistId:'custpage_search_sublist',
fieldId:'entity',
line:i
});
var nameKey = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'entity',
line:i
});
var date =new Date();
var stringDate = date.getDate()+'/'+parseInt(date.getMonth()+1)+'/'+date.getFullYear();
// to create PDF object creation
returnObj[nameKey] ={
bsAmount:bsAmount,
baAmount:baAmount,
bsDocCount:bsDocCount,
baDocCount:baDocCount,
taxAdmin:taxAdmin,
email:email,
name:name,
stringDate:stringDate};
}
}
if(selected==0)
{
message.create({
title : "No data selected",
message : "Please Select atleast one row to Print data",
type : message.Type.INFORMATION
}).show({
duration : 4500
});
}
else
{
// to go back to SL
var get_url = url.resolveScript({
scriptId : "customscript_mbs11_sl_ba_bs_forms",
deploymentId : "customdeploy_mbs11_sl_ba_bs_forms",
returnExternalUrl : false,
params:{
returnObj:JSON.stringify(returnObj),
mode:'download'
}
});
window.open(get_url);
}
}catch(e)
{
console.log("Err@ FN pageInit=",e.message);
}
}
/**
* Function to send mail
*
*/
function sendMailTo()
{
try{
// to get the total line num
var currRecord = currentRecord.get();
var lineNum = currRecord.getLineCount({
sublistId:'custpage_search_sublist'
});
var startDateSelected = currRecord.getText({
fieldId : 'custpage_start_date'
});
var endDateSelected = currRecord.getText({
fieldId : 'custpage_end_date'
});
var amountSelected = currRecord.getValue({
fieldId : 'custpage_amount'
});
var pageIndex = assignDefaultValue(currRecord.getValue({
fieldId: 'pageindexfield'
}), 0);
var selected=0;
var returnObj={};
// to get selected lines
for(var i=0;i<lineNum;i++)
{
var isSelected = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'custpage_select',
line:i
});
if(isSelected==true)
{
selected++;
// get email
var email = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulatext_7',
line:i
});
var taxAdmin = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulatext_2',
line:i
});
//formulanumeric
var baDocCount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulanumeric',
line:i
});
var bsDocCount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulanumeric_5',
line:i
});
var baAmount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulacurrency',
line:i
});
var bsAmount = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'formulacurrency_6',
line:i
});
var name = currRecord.getSublistText({
sublistId:'custpage_search_sublist',
fieldId:'entity',
line:i
});
var nameKey = currRecord.getSublistValue({
sublistId:'custpage_search_sublist',
fieldId:'entity',
line:i
});
var date =new Date();
var stringDate = date.getDate()+'/'+parseInt(date.getMonth()+1)+'/'+date.getFullYear();
// to create PDF object creation
returnObj[nameKey] ={
bsAmount:bsAmount,
baAmount:baAmount,
bsDocCount:bsDocCount,
baDocCount:baDocCount,
taxAdmin:taxAdmin,
email:email,
name:name,
stringDate:stringDate};
}
}
if(selected==0)
{
message.create({
title : "No entry selected",
message : "Please Select atleast one row to send mail",
type : message.Type.INFORMATION
}).show({
duration : 4500
});
}
else
{
// to go back to SL
var get_url = url.resolveScript({
scriptId : "customscript_mbs11_sl_ba_bs_forms",
deploymentId : "customdeploy_mbs11_sl_ba_bs_forms",
returnExternalUrl : false,
params:{
returnObj:JSON.stringify(returnObj),
mode:'send'
}
});
get_url += '&startDateSelected=' + startDateSelected
+ '&endDateSelected=' + endDateSelected
+'&amountSelected='+ amountSelected
+ '&pageindexfield=' + pageIndex;
window.location.href=get_url;
message.create({
title : "Please wait...",
message : "Initiated sending mail action...It may take some time to execute...",
type : message.Type.INFORMATION
}).show({
duration : 4500
});
}
}catch(e)
{
console.log("Err@ FN =",e.message);
}
}
/**
* Function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @since 2015.2
*/
function fieldChanged(scriptContext) {
try {
var fieldIdObj = {
'pageindexfield' : 'pageindexfield'
};
if (checkForParameter(fieldIdObj[scriptContext.fieldId])) {
var skipWaitPromise = new Promise(function(resolve,
reject) {
resolve(scriptContext);
});
setTimeout(function() {
runPromise(skipWaitPromise);
}, 10);
}
return true;
} catch (e) {
console.log("Err @field Change", e);
}
}
function runPromise(skipWaitPromise) {
try {
skipWaitPromise.then(function(scriptContext) {
return displayResult(false);
});
} catch (e) {
console.log("Err @runPromise", e);
}
}
/**
* Function to be executed when field is slaved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
*
* @since 2015.2
*/
function postSourcing(scriptContext) {
}
/**
* Function to be executed after sublist is inserted, removed, or edited.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @since 2015.2
*/
function sublistChanged(scriptContext) {
}
/**
* Function to be executed after line is selected.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @since 2015.2
*/
function lineInit(scriptContext) {
}
/**
* Validation function to be executed when field is changed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
* @param {string} scriptContext.fieldId - Field name
* @param {number} scriptContext.lineNum - Line number. Will be undefined if not a sublist or matrix field
* @param {number} scriptContext.columnNum - Line number. Will be undefined if not a matrix field
*
* @returns {boolean} Return true if field is valid
*
* @since 2015.2
*/
function validateField(scriptContext) {
}
/**
* Validation function to be executed when sublist line is committed.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateLine(scriptContext) {
}
/**
* Validation function to be executed when sublist line is inserted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateInsert(scriptContext) {
}
/**
* Validation function to be executed when record is deleted.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @param {string} scriptContext.sublistId - Sublist name
*
* @returns {boolean} Return true if sublist line is valid
*
* @since 2015.2
*/
function validateDelete(scriptContext) {
}
/**
* Validation function to be executed when record is saved.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.currentRecord - Current form record
* @returns {boolean} Return true if record is valid
*
* @since 2015.2
*/
function saveRecord(scriptContext) {
}
/*********************************************
* To assign a default value if the it is empty
* @param value
* @param defaultValue
* @returns
********************************************/
function assignDefaultValue(value, defaultValue) {
try{
if (checkForParameter(value))
return value;
else
return defaultValue;
}catch(e)
{
log.debug("Err@ FN assignDefaultValue",e);
}
}
function displayResult(ignore) {
try {
var get_url = url.resolveScript({
scriptId : "customscript_mbs11_sl_ba_bs_forms",
deploymentId : "customdeploy_mbs11_sl_ba_bs_forms",
returnExternalUrl : false
});
var currRecord = currentRecord.get();
var startDateSelected = currRecord.getText({
fieldId : 'custpage_start_date'
});
var endDateSelected = currRecord.getText({
fieldId : 'custpage_end_date'
});
var amountSelected = currRecord.getValue({
fieldId : 'custpage_amount'
});
var pageIndex = assignDefaultValue(currRecord.getValue({
fieldId: 'pageindexfield'
}), 0);
if (((startDateSelected == null || startDateSelected == ""
|| startDateSelected == " "
|| startDateSelected == ' '
|| startDateSelected == undefined || startDateSelected == '')
&& (endDateSelected == null
|| endDateSelected == ""
|| endDateSelected == " "
|| endDateSelected == ' '
|| endDateSelected == undefined || endDateSelected == '')
&& (amountSelected == null
|| amountSelected == ""
|| amountSelected == " "
|| amountSelected == ' '
|| amountSelected == undefined || amountSelected == ''))&& ignore!=false) {
message.create({
title : "No filter applied",
message : "Please Select Start date or End date or Amount",
type : message.Type.INFORMATION
}).show({
duration : 4500
});
} else {
get_url += '&startDateSelected=' + startDateSelected
+ '&endDateSelected=' + endDateSelected
+'&amountSelected='+ amountSelected
+ '&pageindexfield=' + pageIndex;
window.location.href = get_url;
return true;
}
} catch (e) {
console.log("Err@ FN =", e.message);
}
}
/**********************************************
* for getting parameter by name .................
*
**********************************************/
function getParameterByName(name, url) {
if (!url)
url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
.exec(url);
if (!results)
return null;
if (!results[2])
return ' ';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
/**********************************************
* 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;
} else {
if (parameterName)
console.log('Empty Value found for parameter'
+ parameterName);
return false;
}
}
return {
pageInit: pageInit,
fieldChanged : fieldChanged,
displayResult:displayResult,
sendMailTo:sendMailTo,
printData:printData
};
});