Jira code: UMAR-14
This script is for Setting buttons’ Order Lost’, ‘Unable to quote’, Request, Change Status, Send, Complete, Proforma Invoice, Packing List, Vendor Bill, Customer Sales Invoice, and Commission Invoice in Sub Job View view mode. Also disabling the tabs and buttons on specific conditions.
User Event Script
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
* @author Jobin and Jismi IT services LLP
*/
/**
* Script Description: This script for Setting buttons in sub job
* setting buttons 'Order Lost', 'Unable to quote' in view mode
*/
/*******************************************************************************
* * UMAR WSR * *
* **************************************************************************
* Date:14/3/18
* Script name: NetU UE Sub Job
* Script id: customscript_netu_ue_sub_job
* Deployment id: customdeploy_netu_ue_sub_job
* Applied to: Sub Job Record
*
******************************************************************************/
define(['N/record', 'N/search', 'N/runtime'],
function(record, search, runtime) {
/**
* Function definition to be triggered before record is loaded.
*
* @param {Object} scriptContext
* @param {Record} scriptContext.newRecord - New record
* @param {string} scriptContext.type - Trigger type
* @param {Form} scriptContext.form - Current form
* @Since 2015.2
*/
function beforeLoad(scriptContext) {
try {
var form = scriptContext.form;
var recId = scriptContext.newRecord.id;
log.debug('recId', recId);
//Getting the sub job status
var sjRecDtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: recId,
columns: ['custrecord_netu_subjob_status', 'custrecord_netu_subjob_invoice_type', 'custrecord_netu_po_readiness_date',
'custrecord_netu_so_req_delivery_date', 'custrecordnetu_po_delivery_instr_date', 'custrecord_netu_po_requ_desp_det_date',
'custrecord_netu_so_desp_det_date', 'custrecord_netu_subjob_subsidiary'
]
});
var st = null;
if (sjRecDtls.custrecord_netu_subjob_status != null) {
st = sjRecDtls.custrecord_netu_subjob_status[0].value;
}
if (sjRecDtls.custrecord_netu_subjob_invoice_type != null) {
type = sjRecDtls.custrecord_netu_subjob_invoice_type[0].value;
}
if (sjRecDtls.custrecord_netu_subjob_subsidiary != null) {
subsidiary = sjRecDtls.custrecord_netu_subjob_subsidiary[0].value;
}
//getting values in date fields of logistics
var fieldArray = [sjRecDtls.custrecord_netu_po_readiness_date, sjRecDtls.custrecord_netu_so_req_delivery_date, sjRecDtls.custrecordnetu_po_delivery_instr_date, sjRecDtls.custrecord_netu_po_requ_desp_det_date, sjRecDtls.custrecord_netu_so_desp_det_date];
var resultArray = [];
for (var j = 0; j < 5; j++) {
log.debug('fieldArray[j]', fieldArray[j]);
if ((fieldArray[j] != null) && (fieldArray[j] != "") && (fieldArray[j] != undefined)) {
log.debug('fieldArray[j]2', fieldArray[j]);
resultArray[j] = fieldArray[j];
} else { resultArray[j] = ''; }
}
if (scriptContext.type == 'view') {
form.clientScriptFileId = 1866;
//ADDING PROGRESS BAR FOR INVOICE CREATION BUTTONS
var progressBarField = form.addField({
id: 'custpage_progress_bar',
type: 'INLINEHTML',
label: 'Progress bar'
});
var loadingUrl = "https://system.eu2.netsuite.com/core/media/media.nl?id=2461&c=4817421&h=1461eeba51aacda4dba5";
var html = "<div><img id='custpage_load_img' style='height:40px;width:100px;top: 122px;left: 893px;float: right;position: absolute;display: none;' src='" + loadingUrl + "'/></div>";
progressBarField.defaultValue = html;
log.debug('html', html);
//order lost button
var orderLostBtn = form.addButton({
id: 'custpage_order_lost_btn_sb',
label: 'Order Lost',
functionName: 'changeStatustoLostOrder'
});
//unable to quote button
var unableQuoteBtn = form.addButton({
id: 'custpage_unable_quote_btn_sb',
label: 'Unable to quote',
functionName: 'changeStatustoUnableQuote'
});
if ((st == 10) || (st == 4) || (st == 20)) {
orderLostBtn.isDisabled = true;
unableQuoteBtn.isDisabled = true;
}
//Getting The role of current User
var userRole = runtime.getCurrentUser().role;
if (((st == 10) || (st == 20) || (st == 4)) && (userRole != 3)) {
//remove the edit button if the status is subjob cancelled or unable to quote or order lost and Not Administrator Role.
form.removeButton({
id: 'edit'
});
form.removeButton({
id: 'secondaryedit'
});
//disabling the sub tabs if the status is order lost or cancel and Not Administrator Role.
var jobField = form.addField({
id: 'custpage_jobid',
type: 'INLINEHTML',
label: 'Job Id'
});
var html = "<script>jQuery( document ).ready(function() { jQuery('#main_form').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('.subtabblock').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('.uir-secondary-buttons').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('#div_CREATENEW_d1').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('#div_ACTIONMENU_d1').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('#div_secondaryCREATENEW_d1').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('#div_secondaryACTIONMENU_d1').css('pointer-events', 'none'); });</script>";
jobField.defaultValue = html;
}
//logistics is only for the UMAR
if (subsidiary == 1 || subsidiary == 2) {
//adding the logistics button
var request = form.addButton({
id: 'custpage_request',
label: 'Request',
functionName: 'Request'
});
var chnageStatus = form.addButton({
id: 'custpage_save_change',
label: 'Change Status',
functionName: 'ChangeStatusLogistics'
});
var send = form.addButton({
id: 'custpage_send',
label: 'Send',
functionName: 'sendRequest'
});
var complete = form.addButton({
id: 'custpage_complete',
label: 'Complete',
functionName: 'completeAction'
});
var proformaInvoice = form.addButton({
id: 'custpage_proforma_invoice',
label: 'Proforma Invoice',
functionName: 'proformaInvoice'
});
var packingList = form.addButton({
id: 'custpage_packing_list',
label: 'Packing List',
functionName: 'packingList'
});
request.isDisabled = true;
//chnageStatus.isDisabled = true;
send.isDisabled = true;
complete.isDisabled = true;
proformaInvoice.isDisabled = true;
packingList.isDisabled = true;
//Request button enabling
if ((st == 11) || (st == 13) || (st == 15)) {
request.isDisabled = false;
}
//Request button disabling
if ((st == 12 && resultArray[0]) || (st == 13 && resultArray[1]) || (st == 15 && resultArray[3])) {
request.isDisabled = true;
}
//changestatus button enabling
// if ((st == 12) || (st == 13 && resultArray[1]) || (st == 14 && resultArray[2]) || (st == 15 && resultArray[3])) {
if (st >= 17) {
chnageStatus.isDisabled = true;
}
//send button enabling
if ((st == 14 && !resultArray[2]) || (st == 16 && !resultArray[4])) {
send.isDisabled = false;
}
//if (st == 16 && resultArray[4]) {
if (st == 16) {
complete.isDisabled = false;
}
//proformaInvoice button enabling
if ((st >= 6) && (st != 22)) {
proformaInvoice.isDisabled = false;
packingList.isDisabled = false;
}
}
log.debug('subsidiary', subsidiary);
if (subsidiary == 3) {
var complete = form.addButton({
id: 'custpage_complete',
label: 'Complete',
functionName: 'completeAction'
});
complete.isDisabled = false;
}
if(st>=17){complete.isDisabled = true;}
//setting invoice buttons if the (status is before invoice and subsidiary is umar) or (subsidiary is wsr)
if ((st >= 17 && subsidiary == 1) || (st >= 17 && subsidiary == 2) || (st >= 17 && subsidiary == 3)) {
var vendbill = form.addButton({
id: 'custpage_vendor_bill',
label: 'Vendor Bill',
functionName: 'vendorBill'
});
var saleinvoice = form.addButton({
id: 'custpage_sales_invoice',
label: 'Customer Sales Invoice',
functionName: 'customerSalesInvoice'
});
var commi_invoice = form.addButton({
id: 'custpage_commission_invoice',
label: 'Commission Invoice',
functionName: 'commissionInvoice'
});
vendbill.isDisabled = true;
saleinvoice.isDisabled = true;
commi_invoice.isDisabled = true;
if (type == 1) {
vendbill.isDisabled = false;
saleinvoice.isDisabled = false;
}
if (type == 2) {
// saleinvoice.isDisabled = false;
commi_invoice.isDisabled = false;
}
if (type == 3) {
vendbill.isDisabled = false;
saleinvoice.isDisabled = false;
commi_invoice.isDisabled = false;
}
var salesorderSearchObj1 = search.create({
type: "transaction",
filters: [
["custbody_netu_subjob", "anyof", recId],
"AND",
["type", "anyof", "SalesOrd", "PurchOrd"],
"AND",
["mainline", "is", "T"]
],
columns: [
search.createColumn({ name: "internalid", label: "Internal ID" }),
search.createColumn({ name: "recordtype", label: "Record Type" }),
search.createColumn({ name: "statusref", label: "Status" })
]
});
var searchResultCount = salesorderSearchObj1.runPaged().count;
if (searchResultCount != 0) {
var salesResults = salesorderSearchObj1.run().getRange({
start: 0,
end: 2
});
recType = salesResults[0].getValue({
name: 'recordtype'
});
recStatus = salesResults[0].getValue({
name: 'statusref'
});
if (recType == 'salesorder') {
if ((recStatus == 'fullyBilled') || (recStatus == 'closed')) {
saleinvoice.isDisabled = true;
commi_invoice.isDisabled = true;
}
} else if (recType == 'purchaseorder') {
if ((recStatus == 'fullyBilled') || (recStatus == 'closed')) {
vendbill.isDisabled = true;
}
}
log.debug({
title: 'recType recStatus',
details: recType + ' ' + recStatus
});
recType = salesResults[1].getValue({
name: 'recordtype'
});
recStatus = salesResults[1].getValue({
name: 'statusref'
});
log.debug({
title: 'recType recStatus',
details: recType + ' ' + recStatus
});
if (recType == 'salesorder') {
if ((recStatus == 'fullyBilled') || (recStatus == 'closed')) {
saleinvoice.isDisabled = true;
commi_invoice.isDisabled = true;
}
} else if (recType == 'purchaseorder') {
if ((recStatus == 'fullyBilled') || (recStatus == 'closed')) {
vendbill.isDisabled = true;
}
}
}
}
}
if (scriptContext.type == 'edit') {
try {
//disabling the logistics fields
if (st >= 13) {
var logisticesField = form.addField({
id: 'custpage_req_readiness',
type: 'INLINEHTML',
label: 'Logistices Field'
});
var html = "<script>jQuery( document ).ready(function() { jQuery('#tr_fg_fieldGroup162').css('pointer-events', 'none'); });</script>";
if (st >= 14) {
html += "<script>jQuery( document ).ready(function() { jQuery('#tr_fg_fieldGroup163').css('pointer-events', 'none'); });</script>";
}
if (st >= 15 && resultArray[2]) {
html += "<script>jQuery( document ).ready(function() { jQuery('#tr_fg_fieldGroup164').css('pointer-events', 'none'); });</script>";
}
if (st >= 16 && resultArray[3]) {
html += "<script>jQuery( document ).ready(function() { jQuery('#tr_fg_fieldGroup165').css('pointer-events', 'none'); });</script>";
}
if (st >= 17 && resultArray[4]) {
html += "<script>jQuery( document ).ready(function() { jQuery('#custrecord_netu_so_desp_det_date_fs').css('pointer-events', 'none'); });" +
"jQuery( document ).ready(function() { jQuery('#custrecord_netu_so_despatch_det_remarks').css('pointer-events', 'none'); });</script>";
}
logisticesField.defaultValue = html;
}
} catch (e) {
log.debug({
title: 'e.name',
details: e.message
});
}
}
} catch (e) {
log.debug({
title: 'e.name',
details: e.message
});
}
}
return {
beforeLoad: beforeLoad
};
});
Client Script
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script defining the function of button
*/
/*******************************************************************************
* * UMAR WSR * *
* **************************************************************************
* Date:10/3/18
* Script name: NetU CS Subjob Actions
* Script id: customscript_netu_cs_subjob_actions
* Deployment id: customdeploy_netu_cs_subjob_actions
* Applied to: Sub Job
*
******************************************************************************/
define(['N/currentRecord', 'N/record', 'N/runtime', 'N/search', 'N/error', 'N/url', 'N/https', 'N/format'],
function(currentRecord, record, runtime, search, e, url, https, format) {
/**
* 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
*/
var temp = '';
var taskid = '';
var buttonId = '';
function pageInit(scriptContext) {
var currentRecord = scriptContext.currentRecord;
var subValue = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_status'
});
if ((subValue >= 11) && (subValue < 17)) {
var subssta = currentRecord.getField({
fieldId: 'custrecord_netu_subjob_status'
});
subssta.isDisabled = false;
}
}
/* AJ ends*/
function validateField(scriptContext) {
try {
var currentRecord = scriptContext.currentRecord;
var recId = currentRecord.id;
if (scriptContext.fieldId == 'custrecord_netu_subjob_customer_ref') {
var customerRef = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_customer_ref'
});
var customerSecdRef = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_cust_2nd_ref'
});
customerRef = customerRef.replace(/(^\s*)|(\s*$)/gi, "");
customerRef = customerRef.replace(/[ ]{2,}/gi, " ");
customerRef = customerRef.replace(/\n /, "\n");
if (customerSecdRef == '' || customerSecdRef == null || customerSecdRef == undefined) {} else {
if (customerRef.toUpperCase() == customerSecdRef.toUpperCase()) {
console.log('customerRef.toUppe' + ',' + customerRef.toUpperCase() + ',' + customerSecdRef.toUpperCase());
alert('Customer Reference Already Exists in current record');
currentRecord.setValue({
fieldId: 'custrecord_netu_subjob_customer_ref',
value: null,
ignoreFieldChange: false
});
return false;
}
}
var customer = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_customer'
});
var vessel = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_vessel'
});
var mainjobNo = currentRecord.getValue({
fieldId: 'custrecord_netu_main_job'
});
var vesselNames = getJobsWithCustomerReference(customerRef, recId, customer, vessel, mainjobNo);
//console.log('vesselNames',vesselNames);
if (vesselNames == '' || vesselNames == null || vesselNames == undefined) {} else {
alert('Customer Reference Already Exists ' + vesselNames);
currentRecord.setValue({
fieldId: 'custrecord_netu_subjob_customer_ref',
value: null,
ignoreFieldChange: true
});
return false;
}
}
if (scriptContext.fieldId == 'custrecord_netu_subjob_cust_2nd_ref') {
var customerRefN = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_customer_ref'
});
var customerSecdRefN = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_cust_2nd_ref'
});
customerSecdRefN = customerSecdRefN.replace(/(^\s*)|(\s*$)/gi, "");
customerSecdRefN = customerSecdRefN.replace(/[ ]{2,}/gi, " ");
customerSecdRefN = customerSecdRefN.replace(/\n /, "\n");
if (customerRefN == '' || customerRefN == null || customerRefN == undefined) {} else {
if (customerSecdRefN.toUpperCase() == customerRefN.toUpperCase()) {
console.log('customerRef.toUppe' + ',' + customerSecdRefN.toUpperCase() + ',' + customerRefN.toUpperCase());
alert('Customer Reference Already Exists in current record');
currentRecord.setValue({
fieldId: 'custrecord_netu_subjob_cust_2nd_ref',
value: null,
ignoreFieldChange: true
});
return false;
}
}
var customer = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_customer'
});
var vessel = currentRecord.getValue({
fieldId: 'custrecord_netu_subjob_vessel'
});
var mainjobNo = currentRecord.getValue({
fieldId: 'custrecord_netu_main_job'
});
var vesselNames = getJobsWithCustomerReference(customerSecdRefN, recId, customer, vessel, mainjobNo);
console.log('vesselNames');
console.log('vesselNames', vesselNames);
if (vesselNames == '' || vesselNames == null || vesselNames == undefined) {} else {
alert('Customer Reference Already Exists ' + vesselNames);
currentRecord.setValue({
fieldId: 'custrecord_netu_subjob_cust_2nd_ref',
value: null,
ignoreFieldChange: true
});
return false;
}
}
return true;
} catch (e) {
console.log(e.message);
}
}
/*
* Function to change the sub job status in all related records
*/
function changeStatus(subjobId, st) {
try {
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_change_status',
deploymentId: 'customdeploy_netu_sl_change_status',
returnExternalUrl: false,
}) + '&subJobId=' + subjobId + '&statusNo=' + st;
console.log('SL:', output);
https.get({
url: output
});
} catch (e) {
console.log(e.message);
}
}
/*
* Function defining the action of Order Lost button
*/
function changeStatustoLostOrder() {
try {
var cnfm = confirm("Do you want to continue with Order Lost?");
if (cnfm == true) {
console.log("True");
//Getting current record id
var currentRec = currentRecord.get();
var subjobId = currentRec.id;
//Change the sub job status to Order lost
var subRecId = record.submitFields({
type: 'customrecord_netu_sub_job',
id: subjobId,
values: {
'custrecord_netu_subjob_status': '10'
}
});
console.log('subjobId', subRecId);
window.location.reload(true);
var st = '10';
changeStatus(subjobId, st);
}
} catch (e) {
console.log(e.message);
}
}
/*
* Function defining the action of Unable To Quote button
*/
function changeStatustoUnableQuote() {
try {
var cnfm = confirm("Do you want to continue with Unable To Quote?");
if (cnfm == true) {
console.log("True");
//Getting current record id
var currentRec = currentRecord.get();
var subjobId = currentRec.id;
//Change the sub job status to Unable To Quote
var subRecId = record.submitFields({
type: 'customrecord_netu_sub_job',
id: subjobId,
values: {
'custrecord_netu_subjob_status': '4'
}
});
console.log('subjobId', subRecId);
window.location.reload(true);
var st = '4';
changeStatus(subjobId, st);
}
} catch (e) {
console.log(e.message);
}
}
/**
* 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) {
try {
var currRecord = currentRecord.get();
var subjobId = currRecord.id;
var flag = true;
//Getting the new value of sub job type
var subjobType = currRecord.getValue({
fieldId: 'custrecord_netu_subjob_type'
});
//Getting the Saved value of sub job type
var subJobdtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: subjobId,
columns: ['custrecord_netu_subjob_type']
});
var jobType = null;
if (subJobdtls.custrecord_netu_subjob_type != null) {
jobType = subJobdtls.custrecord_netu_subjob_type[0].value;
}
if (jobType != subjobType) {
var cnfm = confirm("The Sub job Type has changed. Do you really want to submit it?");
if (cnfm == true) {
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_item_copy',
deploymentId: 'customdeploy_netu_sl_item_copy',
returnExternalUrl: false,
}) + '&subJobId=' + subjobId + '&jobType=' + jobType + '&subjobType=' + subjobType;
console.log('SL:', output);
https.get({
url: output
});
flag = true;
} else {
flag = false;
}
}
return flag;
} catch (e) {
console.log(e.message);
}
}
//function for creating customer sales invoice
function customerSalesInvoice() {
try {
jQuery("#custpage_load_img").css("display", "block")
document.getElementById("custpage_sales_invoice").disabled = true;
var currentRec = currentRecord.get();
var recordid = currentRec.id;
var subjobStatus = currentRec.getValue({
fieldId: 'custrecord_netu_subjob_status'
});
var manjobNo = currentRec.getValue({
fieldId: 'custrecord_netu_main_job'
});
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_create_flow_invoice',
deploymentId: 'customdeploynetu_sl_create_flow_invoice',
returnExternalUrl: false,
}) + '&recId=' + recordid + '&type=1' + '&status=' + subjobStatus;
https.get.promise({
url: output
}).then(function(response) {
var jsonResponse = JSON.parse(response.body);
jQuery("#custpage_load_img").css("display", "none");
if (jsonResponse.recordurl) {
if (subjobStatus == 17) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recordid,
values: {
'custrecord_netu_subjob_status': '18'
}
});
record.submitFields({
type: 'customrecord_netu_main_job',
id: manjobNo,
values: {
'custrecord_netu_job_status': '6'
}
});
}
window.open(jsonResponse.recordurl);
} else {
alert(jsonResponse.errorMessage);
}
}).catch(function onRejected(reason) {
console.log(reason);
})
} catch (e) {
console.log(e.message);
}
}
//function for creating vendor bill
function vendorBill() {
try {
jQuery("#custpage_load_img").css("display", "block")
document.getElementById("custpage_vendor_bill").disabled = true;
var currentRec = currentRecord.get();
var recordid = currentRec.id;
var subjobStatus = currentRec.getValue({
fieldId: 'custrecord_netu_subjob_status'
});
var manjobNo = currentRec.getValue({
fieldId: 'custrecord_netu_main_job'
});
//jQuery('#custpage_flow_invoice').css('opacity', '0.5').css('pointer-events', 'none');
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_create_flow_invoice',
deploymentId: 'customdeploynetu_sl_create_flow_invoice',
returnExternalUrl: false,
}) + '&recId=' + recordid + '&type=2' + '&status=' + subjobStatus;
https.get.promise({
url: output
})
.then(function(response) {
var jsonResponse = JSON.parse(response.body);
jQuery("#custpage_load_img").css("display", "none");
// var obj = JSON.parse(response.body);
if (jsonResponse.recordurl) {
if (subjobStatus == 17) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recordid,
values: {
'custrecord_netu_subjob_status': '18'
}
});
record.submitFields({
type: 'customrecord_netu_main_job',
id: manjobNo,
values: {
'custrecord_netu_job_status': '6'
}
});
}
window.open(jsonResponse.recordurl);
//window.location = jsonResponse.recordurl;
} else {
alert(obj.id);
}
})
.catch(function onRejected(reason) {
alert(jsonResponse.errorMessage);
})
} catch (e) {
console.log(e.message);
}
}
//function for creating vendor commission invoice
function commissionInvoice() {
try {
jQuery("#custpage_load_img").css("display", "block")
document.getElementById("custpage_commission_invoice").disabled = true;
var currentRec = currentRecord.get();
var recordid = currentRec.id;
var subjobStatus = currentRec.getValue({
fieldId: 'custrecord_netu_subjob_status'
});
var manjobNo = currentRec.getValue({
fieldId: 'custrecord_netu_main_job'
});
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_create_flow_invoice',
deploymentId: 'customdeploynetu_sl_create_flow_invoice',
returnExternalUrl: false,
}) + '&recId=' + recordid + '&type=3' + '&status=' + subjobStatus;
https.get.promise({
url: output
})
.then(function(response) {
var jsonResponse = JSON.parse(response.body);
jQuery("#custpage_load_img").css("display", "none");
if (jsonResponse.recordurl) {
if (subjobStatus == 17) {
record.submitFields({
type: 'customrecord_netu_sub_job',
id: recordid,
values: {
'custrecord_netu_subjob_status': '18'
}
});
record.submitFields({
type: 'customrecord_netu_main_job',
id: manjobNo,
values: {
'custrecord_netu_job_status': '6'
}
});
}
window.open(jsonResponse.recordurl);
//window.location = jsonResponse.recordurl;
} else {
alert(jsonResponse.errorMessage);
}
}).catch(function onRejected(reason) {
console.log(reason);
})
} catch (e) {
console.log(e.message);
}
}
/*
* Function to check the existence of the customer reference
*/
function getJobsWithCustomerReference(customerRef, recId, customer, vessel, mainjobNo) {
try {
var isExists = false;
var isExistsFlag = 0;
if (recId == '') {
recId = 0;
}
if (customer == '') {
customer = 0;
}
if (vessel == '') {
vessel = 0;
}
console.log('mainjobNo',mainjobNo);
//Check for Existence only if the Reference field is not empty
if (customerRef != '') {
var jobSearch = search.create({
type: "customrecord_netu_main_job",
filters: [
[
["custrecord_netu_customer", "anyof", customer], "AND", ["custrecord_netu_vessel", "anyof", vessel]
],
"AND",
["internalidnumber","notequalto", mainjobNo],
"AND",
[
["custrecord_netu_customer_reference", "is", customerRef], "OR", ["custrecord_netu_2nd_reference", "is", customerRef]
]
],
columns: [
search.createColumn({
name: "name",
sort: search.Sort.ASC,
label: "ID"
}),
search.createColumn({ name: "custrecord_netu_vessel", label: "Vessel" })
/*,
search.createColumn({name: "custrecord_netu_subjob_vendor", label: "Vendor"})*/
]
});
var jobResults = jobSearch.run().getRange({
start: 0,
end: 10
});
isExists = false;
if (jobResults != null) {
if (jobResults.length > 0) {
/*isExists = true;
return isExists;*/
var ref = jobResults[0].getValue({
name: "name"
});
ref = 'Main Job# ' + ref;
isExists = true;
isExistsFlag = 1;
return ref;
}
}
//****************************************
var jobSearch = search.create({
type: "customrecord_netu_sub_job",
filters: [
[
["custrecord_netu_main_job.internalidnumber","notequalto",mainjobNo], "AND", ["custrecord_netu_subjob_customer", "anyof", customer], "AND", ["custrecord_netu_subjob_vessel", "anyof", vessel]
],
"AND",
[
["custrecord_netu_subjob_customer_ref", "is", customerRef], "OR", ["custrecord_netu_subjob_cust_2nd_ref", "is", customerRef]
]
],
columns: [
search.createColumn({
name: "name",
sort: search.Sort.ASC,
label: "ID"
}),
search.createColumn({ name: "custrecord_netu_subjob_vessel", label: "Vessel" })
/*,
search.createColumn({name: "custrecord_netu_subjob_vendor", label: "Vendor"})*/
]
});
var jobResults = jobSearch.run().getRange({
start: 0,
end: 10
});
isExists = false;
if (jobResults != null) {
if (jobResults.length > 0) {
/* isExists = true;
return isExists;*/
var ref = jobResults[0].getValue({
name: "name"
});
ref = 'Sub Job# ' + ref;
isExists = true;
isExistsFlag = 1;
return ref;
}
}
var jobSearch = search.create({
type: "estimate",
filters: [
["type", "anyof", "Estimate"],
"AND",
["custbody_netu_customer", "anyof", customer],
"AND",
["custbody_netu_vessel", "anyof", vessel],
"AND",
["custbody_netu_main_job.internalidnumber","notequalto",mainjobNo],
"AND",
[
["custbody_netu_customer_reference", "is", customerRef],
"OR",
["custbody_netu_customer_2nd_ref", "is", customerRef]
]
],
columns: [
search.createColumn({
name: "name",
sort: search.Sort.ASC,
label: "ID"
}),
search.createColumn({ name: "custbody_netu_vessel", label: "Vessel" }),
//search.createColumn({name: "custrecord_netu_subjob_vendor", label: "Vendor"})
]
});
var jobResults = jobSearch.run().getRange({
start: 0,
end: 10
});
console.log('jobResults', jobResults.length);
isExists = false;
if (jobResults != null) {
console.log('in');
if (jobResults.length > 0) {
var ref = jobResults[0].getValue({
name: "tranid"
});
ref = 'Quotation# ' + ref;
isExistsFlag = 1;
return ref;
}
}
}
if (isExistsFlag == 0) {
return isExists;
}
} catch (e) {
console.log(e.message);
}
}
/*
* Request button actions
*/
function Request() {
try {
var currentRec = currentRecord.get();
var id = currentRec.id;
var currentStatus = null;
//Getting the Invoice Type
var sjRecDtlscnt = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_status']
});
if (sjRecDtlscnt.custrecord_netu_subjob_status[0] != null) {
currentStatus = sjRecDtlscnt.custrecord_netu_subjob_status[0].value;
}
buttonId = "custpage_request";
// request for readiness to vendor
if (currentStatus == '11') {
temp = 25;
taskid = 7;
mailToVendor(temp, taskid, buttonId);
}
// request for despatch detalis
if (currentStatus == '13') {
temp = 26;
taskid = 5;
mailToCustomer(temp, taskid, buttonId)
}
// request for despatch detalis
if (currentStatus == '15') {
temp = 28;
taskid = 8;
mailToVendor(temp, taskid, buttonId);
}
} catch (e) {
console.log(e.message);
}
}
function ChangeStatusLogistics() {
try {
var currRecord = currentRecord.get();
var id = currRecord.id;
var recordtype = currRecord.type;
var status = null;
//Getting the Invoice status
var sjRecDtlscnt = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_status']
});
if (sjRecDtlscnt.custrecord_netu_subjob_status[0] != null) {
currentStatus = sjRecDtlscnt.custrecord_netu_subjob_status[0].value;
}
document.getElementById('custpage_save_change').disabled = true;
// request for delivery instructions
if (currentStatus == '12' || currentStatus == '11') {
status = '13';
changeStatus(id, status);
window.location.reload(true);
}
// Request dispatch details
else if (currentStatus == '13') {
status = '14';
changeStatus(id, status);
window.location.reload(true);
//jQuery('#tbl_custpage_requestid').show();
}
// Request dispatch details
else if (currentStatus == '14') {
status = '15';
changeStatus(id, status);
window.location.reload(true);
}
// Request dispatch details
else if (currentStatus == '15') {
status = '16';
changeStatus(id, status);
window.location.reload(true);
//jQuery('#tbl_custpage_requestid').show();
}
} catch (e) {
console.log(e.message);
}
}
function sendRequest() {
try {
var currRecord = currentRecord.get();
var id = currRecord.id;
//Getting the Invoice status
var sjRecDtlscnt = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_status']
});
if (sjRecDtlscnt.custrecord_netu_subjob_status[0] != null) {
currentStatus = sjRecDtlscnt.custrecord_netu_subjob_status[0].value;
}
buttonId = "custpage_send";
if (currentStatus == 14) {
temp = 27;
taskid = 4;
mailToVendor(temp, taskid, buttonId);
} else if (currentStatus == 16) {
temp = 29;
taskid = 3;
mailToCustomer(temp, taskid, buttonId);
}
} catch (e) {
console.log(e.message);
}
}
//sending request and details to vendor
function mailToVendor(temp, taskid, buttonId) {
try {
var currRecord = currentRecord.get();
var id = currRecord.id;
document.getElementById(buttonId).disabled = true;
//Getting the Invoice Type
var sjRecDtlscnt = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_vendor_contact', 'custrecord_netu_subjob_vend_contact_cc']
});
var invType = null;
var vendContactcc = null;
var vendorId = null;
var vendorContCC = null;
if (sjRecDtlscnt.custrecord_netu_subjob_vendor_contact[0] != null) {
vendorId = sjRecDtlscnt.custrecord_netu_subjob_vendor_contact[0].value;
}
if (sjRecDtlscnt.custrecord_netu_subjob_vend_contact_cc[0] != null) {
vendContactcc = sjRecDtlscnt.custrecord_netu_subjob_vend_contact_cc[0].value;
}
// getting vendor contact
if ((vendorId == null) || (vendorId == "") || (vendorId == undefined)) {
// alert('vendor contact is missing');
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
// return false;
}
// getting vendor contactCC
if ((vendContactcc == null) || (vendContactcc == "") || (vendContactcc == undefined)) {
// alert('vendor contact CC is missing');
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
//return false;
} else {
var vendCCDtls = search.lookupFields({
type: search.Type.CONTACT,
id: vendContactcc,
columns: ['email']
});
console.log('vendCCDtls', vendCCDtls.email);
if ((vendCCDtls.email == null) || (vendCCDtls.email == "") || (vendCCDtls.email == undefined)) {
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
//return false;
} else {
vendorContCC = vendCCDtls.email;
}
console.log(vendorContCC);
}
// Setting the url of the suitelet script
var output = url
.resolveScript({
scriptId: 'customscript_netu_sl_send_quotation',
deploymentId: 'customdeploy_netu_sl_send_quotation',
returnExternalUrl: false,
}) +
'&recId=' + id
//+ '&custId='+ vendId
+
'&sendStatus=' + taskid +
'&contact=' + vendorId +
'&contactCC=' + vendorContCC +
'&temp=' + temp;
// Opens url on a new Window
newWindow = window.open(output, 'netsuite',
'menubar=1,resizable=1,width=740,height=800');
var timer = setInterval(function() {
if (newWindow.closed) {
// console.log('Reload');
clearInterval(timer);
window.location.reload(true);
}
}, 1000);
} catch (e) {
console.log(e.message);
}
}
//sending request and details to vendor
function mailToCustomer(temp, taskid, buttonId) {
try {
var currRecord = currentRecord.get();
var id = currRecord.id;
document.getElementById(buttonId).disabled = true;
//Getting the Invoice Type
var sjRecDtlscnt = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_customer_contact', 'custrecord_netu_subjob_cust_contact_cc']
});
var invType = null;
var customerId = null;
var customerIdcc = null;
if (sjRecDtlscnt.custrecord_netu_subjob_customer_contact[0] != null) {
customerId = sjRecDtlscnt.custrecord_netu_subjob_customer_contact[0].value;
}
if (sjRecDtlscnt.custrecord_netu_subjob_cust_contact_cc[0] != null) {
customerIdcc = sjRecDtlscnt.custrecord_netu_subjob_cust_contact_cc[0].value;
}
var customerccEmail = '';
// getting vendor contact
if ((customerId == null) || (customerId == "") || (customerId == undefined)) {
//alert('Customer contact is missing');
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
// return false;
}
// getting vendor contactCC
if ((customerIdcc == null) || (customerIdcc == "") || (customerIdcc == undefined)) {
// alert('Customer contact CC is missing');
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
//return false;
} else {
var custCCDtls = search.lookupFields({
type: search.Type.CONTACT,
id: customerIdcc,
columns: ['email']
});
console.log('custCCDtls', custCCDtls.email);
if ((custCCDtls.email == null) || (custCCDtls.email == "") || (custCCDtls.email == undefined)) {
setTimeout(
function() {
document.getElementById(buttonId).disabled = false;
}, 100);
//return false;
} else {
customerccEmail = custCCDtls.email;
}
}
// Setting the url of the suitelet script
var output = url
.resolveScript({
scriptId: 'customscript_netu_sl_send_quotation',
deploymentId: 'customdeploy_netu_sl_send_quotation',
returnExternalUrl: false,
}) +
'&recId=' + id
//+ '&custId='+ vendId
+
'&sendStatus=' + taskid +
'&custcont=' + customerId +
'&custcontcc=' + customerccEmail +
'&temp=' + temp;
// Opens url on a new Window
newWindow = window.open(output, 'netsuite',
'menubar=1,resizable=1,width=740,height=800');
var timer = setInterval(function() {
if (newWindow.closed) {
// console.log('Reload');
clearInterval(timer);
window.location.reload(true);
}
}, 1000);
} catch (e) {
console.log(e.message);
}
}
function completeAction() {
try {
var currRecord = currentRecord.get();
var id = currRecord.id;
var currentStatus = currRecord.getValue({
fieldId: 'custrecord_netu_subjob_status'
});
//Getting the Invoice Type
var sjRecDtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_invoice_type']
});
var invType = null;
if (sjRecDtls.custrecord_netu_subjob_invoice_type != null) {
invType = sjRecDtls.custrecord_netu_subjob_invoice_type[0].value;
}
console.log('invType', invType);
document.getElementById("custpage_complete").disabled = true;
status = '17';
if (invType == 4) {
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_change_so_po_status',
deploymentId: 'customdeploy_netu_sl_change_so_po_status',
returnExternalUrl: false,
}) + '&subJobId=' + id + '&statusNo=' + status;
console.log('SL:', output);
https.get({
url: output
});
} else {
changeStatus(id, status);
}
window.location.reload(true);
} catch (e) {
console.log(e.message);
}
}
function proformaInvoice() {
try {
document.getElementById("custpage_proforma_invoice").disabled = true;
//Getting current record id
var currentRec = currentRecord.get();
var id = currentRec.id;
var salesorderSearchObj1 = search.create({
type: "salesorder",
filters: [
["type", "anyof", "SalesOrd"],
"AND",
["custbody_netu_subjob", "anyof", id],
"AND",
["mainline", "is", "T"]
],
columns: [
search.createColumn({ name: "internalid", label: "Internal ID" })
]
});
var searchResultCount = salesorderSearchObj1.runPaged().count;
var recId = null;
if (searchResultCount != 0) {
var salesResults = salesorderSearchObj1.run().getRange({
start: 0,
end: 1
});
recId = salesResults[0].getValue({
name: 'internalid'
});
} else {
alert('Missing Sales Order');
setTimeout(function() { document.getElementById("custpage_proforma_invoice").disabled = false; }, 100);
return false;
}
var sbDtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_customer_contact', 'custrecord_netu_subjob_cust_contact_cc']
});
console.log('sbDtls', sbDtls);
var customerId = null;
var customerIdcc = null;
var recipientId = null;
var recipientCC = null;
var custId = sbDtls.custrecord_netu_subjob_customer_contact[0];
//getting Customer contact
if ((custId == null) || (custId == "") || (custId == undefined)) {
// alert('Customer contact is missing');
setTimeout(function() { document.getElementById("custpage_proforma_invoice").disabled = false; }, 100);
// return false;
} else {
customerId = custId.value;
console.log('customerId', customerId);
var custDtls = search.lookupFields({
type: search.Type.CONTACT,
id: customerId,
columns: ['email']
});
console.log('custDtls', custDtls.email);
if ((custDtls.email == null) || (custDtls.email == "") || (custDtls.email == undefined)) {
// alert('Email is missing for the Customer Contact');
setTimeout(function() { document.getElementById("custpage_proforma_invoice").disabled = false; }, 100);
// return false;
} else {
recipientId = custDtls.email;
}
console.log(recipientId);
}
var custCCId = sbDtls.custrecord_netu_subjob_cust_contact_cc[0];
//getting customer contact cc
if ((custCCId == null) || (custCCId == "") || (custCCId == undefined)) {
//alert('Customer contact cc is missing');
recipientCC = '';
} else {
customerIdcc = custCCId.value;
console.log('customerIdcc', customerIdcc);
var custDtlscc = search.lookupFields({
type: search.Type.CONTACT,
id: customerIdcc,
columns: ['email']
});
console.log('custDtlscc', custDtlscc.email);
if ((custDtlscc.email == null) || (custDtlscc.email == "") || (custDtlscc.email == undefined)) {
// alert('Email is missing for the Customer Contact CC');
} else {
recipientCC = custDtlscc.email;
}
console.log(recipientCC);
}
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_send_quotation',
deploymentId: 'customdeploy_netu_sl_send_quotation',
returnExternalUrl: false,
}) + '&CurrId=' + id + '&recId=' + recId + '&custemailId=' + customerId + '&custemailIdCC=' + recipientCC + '&sendStatus=14';
//Opens url on a new Window
newWindow = window.open(output, 'netsuite', 'menubar=1,resizable=1,width=740,height=800');
//After newWindow Closed reload the Quote page
var timer = setInterval(function() {
if (newWindow.closed) {
//console.log('Reload');
clearInterval(timer);
window.location.reload(true);
}
}, 1000);
} catch (e) {
console.log(e.message);
}
}
function packingList() {
try {
document.getElementById("custpage_packing_list").disabled = true;
//Getting current record id
var currentRec = currentRecord.get();
var id = currentRec.id;
var salesorderSearchObj1 = search.create({
type: "salesorder",
filters: [
["type", "anyof", "SalesOrd"],
"AND",
["custbody_netu_subjob", "anyof", id],
"AND",
["mainline", "is", "T"]
],
columns: [
search.createColumn({ name: "internalid", label: "Internal ID" })
]
});
var searchResultCount = salesorderSearchObj1.runPaged().count;
var recId = null;
if (searchResultCount != 0) {
var salesResults = salesorderSearchObj1.run().getRange({
start: 0,
end: 1
});
recId = salesResults[0].getValue({
name: 'internalid'
});
} else {
alert('Missing Sales Order');
setTimeout(function() { document.getElementById("custpage_packing_list").disabled = false; }, 100);
return false;
}
var sbDtls = search.lookupFields({
type: 'customrecord_netu_sub_job',
id: id,
columns: ['custrecord_netu_subjob_customer_contact', 'custrecord_netu_subjob_cust_contact_cc']
});
console.log('sbDtls', sbDtls);
var customerId = null;
var customerIdcc = null;
var recipientId = null;
var recipientCC = null;
var custId = sbDtls.custrecord_netu_subjob_customer_contact[0];
//getting Customer contact
if ((custId == null) || (custId == "") || (custId == undefined)) {
// alert('Customer contact is missing');
setTimeout(function() { document.getElementById("custpage_packing_list").disabled = false; }, 100);
// return false;
} else {
customerId = custId.value;
console.log('customerId', customerId);
var custDtls = search.lookupFields({
type: search.Type.CONTACT,
id: customerId,
columns: ['email']
});
console.log('custDtls', custDtls.email);
if ((custDtls.email == null) || (custDtls.email == "") || (custDtls.email == undefined)) {
// alert('Email is missing for the Customer Contact');
setTimeout(function() { document.getElementById("custpage_packing_list").disabled = false; }, 100);
// return false;
} else {
recipientId = custDtls.email;
}
console.log(recipientId);
}
var custCCId = sbDtls.custrecord_netu_subjob_cust_contact_cc[0];
//getting customer contact cc
if ((custCCId == null) || (custCCId == "") || (custCCId == undefined)) {
// alert('Customer contact cc is missing');
recipientCC = '';
} else {
customerIdcc = custCCId.value;
console.log('customerIdcc', customerIdcc);
var custDtlscc = search.lookupFields({
type: search.Type.CONTACT,
id: customerIdcc,
columns: ['email']
});
console.log('custDtlscc', custDtlscc.email);
if ((custDtlscc.email == null) || (custDtlscc.email == "") || (custDtlscc.email == undefined)) {
// alert('Email is missing for the Customer Contact CC');
} else {
recipientCC = custDtlscc.email;
}
console.log(recipientCC);
}
//Setting the url of the suitelet script
var output = url.resolveScript({
scriptId: 'customscript_netu_sl_send_quotation',
deploymentId: 'customdeploy_netu_sl_send_quotation',
returnExternalUrl: false,
}) + '&CurrId=' + id + '&recId=' + recId + '&custemailId=' + customerId + '&custemailIdCC=' + recipientCC + '&sendStatus=15';
//Opens url on a new Window
newWindow = window.open(output, 'netsuite', 'menubar=1,resizable=1,width=740,height=800');
//After newWindow Closed reload the Quote page
var timer = setInterval(function() {
if (newWindow.closed) {
//console.log('Reload');
clearInterval(timer);
window.location.reload(true);
}
}, 1000);
} catch (e) {
console.log(e.message);
}
}
return {
pageInit: pageInit,
validateField: validateField,
saveRecord: saveRecord,
changeStatus: changeStatus,
changeStatustoLostOrder: changeStatustoLostOrder,
changeStatustoUnableQuote: changeStatustoUnableQuote,
customerSalesInvoice: customerSalesInvoice,
commissionInvoice: commissionInvoice,
vendorBill: vendorBill,
Request: Request,
ChangeStatusLogistics: ChangeStatusLogistics,
sendRequest: sendRequest,
completeAction: completeAction,
proformaInvoice: proformaInvoice,
packingList: packingList
};
});