Jira Code :AN-35
On clicking the ‘Lot Number’ button , the POs are searched to find if their location is ‘Aurora Products (QA Inspection)’. If not, then the location is set to ‘Aurora Products (QA Inspection)’. This is the update of AN-15: Auto generate Lot number.
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Aurora Naturals
* AN-15
* Auto Generate LOT Numbers
* **************************************************************************
* Date : 28-01-2019
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script is to define the button action of 'Receive Order' button and to define the field change action
* Date created :28-01-2019
*
* REVISION HISTORY
*
* Revision 1.0 ${28-01-2019} nd : created
* 1.1 ${28-01-2019} nd :updated
* 1.2 ${26-02-2019} nd :updated (to show alert if location is different (AN-26))
* 1.3 ${16-03-2019} nd :updated (to remove the alert and set the specified location if location is
different(AN-35))
******************************************************************************/
define(['N/record','N/url','N/currentRecord','N/https','N/search'],
function(record,url,currentRecord,https,search) {
/**
* 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) {
}
/**
* 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 currentRec = scriptContext.currentRecord;
//Changing the sublist based on the Location and Page index selection
if(scriptContext.fieldId == 'custpage_vendor' || scriptContext.fieldId == 'custpage_pageid')
{
var vendorValue = currentRec.getValue({
fieldId : 'custpage_vendor'
});
var pageIndex = currentRec.getValue({
fieldId : 'custpage_pageid'
});
if(pageIndex != null && pageIndex != '' && pageIndex != undefined){
var pageId = parseInt(pageIndex.split('_')[1]);
}
else{
pageId=0;
}
get_url = url.resolveScript({
scriptId: "customscript_an15_jj_al_receiveorders",
deploymentId: "customdeploy_an15_jj_al_receiveorders",
parameters:{
'vendorValue':vendorValue
}
});
get_url += '&vendorValue=' + vendorValue + '&pageindex=' + pageId;
if (window.onbeforeunload) {
window.onbeforeunload = function() {
null;
};
}
window.location.href = get_url;
}
} catch (e) {
console.log(e.name,e.message);
}
}
function receiveOrder(scriptContext){
try{
var poId_array=[]
var itemR_arr=[]
var cur_record = currentRecord.get();
var numLines = cur_record.getLineCount({
sublistId: 'cust_polist'
});
for(var j = 0; j < numLines; j++){
var selectFieldValue = cur_record.getSublistValue({
sublistId: 'cust_polist',
fieldId: 'custpage_select_po',
line: j
});
if(selectFieldValue == true){
var poId = cur_record.getSublistValue({
sublistId: 'cust_polist',
fieldId: 'cust_internalid',
line: j
});
var binLookup = search.lookupFields({
type: search.Type.PURCHASE_ORDER,
id: poId,
columns: ['location']
});
var PO_location = binLookup.location[0].value
if(PO_location != 9){
var id = record.submitFields({
type: record.Type.PURCHASE_ORDER,
id: poId,
values: {
location:'9'
}
});
}
poId_array.push(poId)
}
}
//julian date
var julianDate = Math.floor((new Date().getTime() - new Date("01/01/"+new Date().getFullYear()).getTime())/(1000*60*60*24)+1)
// date code
var jDate = leftPad(julianDate,3)
var str_jDsate= jDate.toString();
//year code
var year = new Date().getFullYear().toString().substr(-2)
var str_year =year.toString();
var jDate_param = str_year.concat(str_jDsate)
var poId_array_encode = encodeURI(poId_array)
var output = url.resolveScript({
scriptId: 'customscript_an15_jj_sl_potoir',
deploymentId: 'customdeploy_an15_jj_sl_potoir',
params:{
'poId':poId_array_encode,
'dateCode':jDate_param
}
});
var response=https.get({
url: output
});
var obj = JSON.parse(response.body);
var itemR_arr = encodeURIComponent(obj.arr_IR)
var ponum_arr = encodeURIComponent(obj.arr_po)
var ir_tranidArr = encodeURIComponent(obj.itemreceipt)
var noIR_puchaseOrder = encodeURIComponent(obj.noIR_PO)
if(obj.id == 'Completed'){
window.location.reload();
}
if (window.onbeforeunload) {
window.onbeforeunload = function() {
null;
};
}
var output_link = url.resolveScript({
scriptId: 'customscript_an19_jj_sl_display_itemrece',
deploymentId: 'customdeploy_an19_jj_sl_display_itemrece',
params:{
'itemReceiptId':itemR_arr,
'poId':ponum_arr,
'tranidIR':ir_tranidArr,
'po_noIR':noIR_puchaseOrder
}
});
window.open(output_link);
//padding zero to make it 3 digit
function leftPad(number, targetLength) {
var output = number + '';
while (output.length < targetLength) {
output = '0' + output;
}
return output;
}
}catch(err){
console.log('error @ receiveOrder',err)
}
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged,
receiveOrder: receiveOrder
};
});