Jira Code: AN-49:
Does not allow inventory items to be bought unless they have all “inventory setup” checkboxes checked. (In PO)
Checkboxes that must be checked for inventory items are:
Item Number, Name, Misc.
Allergens
Standard Cost.
Does not allow an assembly item to be put into a sales order unless it has all “inventory setup” checkboxes checked
Checkboxes that must be checked for assembly items are:
Item Number, Name, Misc.
BOM
Allergens
Routings
Standard Cost.
Client Script : AN-2 CS PO Button Action
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/*******************************************************************************
* CLIENTNAME:Aurora Naturals
* AN-37
* Raw Material Tag only for received items
* **************************************************************************
* Date : 02-11-2018
*
* Author: Jobin & Jismi IT Services LLP
* Script Description : This script defining the function of button
* Date created : 02-11-2018
*
* REVISION HISTORY
*
* Revision 1.0 ${02-11-2018} angel : created
* Revision 1.1 ${20-03-2019} nd : updated
* Revision 1.2 ${04-04-2019} nd : updated for AN-43
* Revision 1.3 ${11-04-2019} nd : updated for AN-46
* Revision 1.4 ${24-04-2019} nd : updated for AN-49
******************************************************************************/
define(['N/currentRecord','N/record','N/url','N/search'],
function(currentRecord,record,url,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) {
try {
} catch (e) {
console.log(e.name,e.message);
}
}
//updated on 20-03-2019
function rowMaterialTag() {
try {
var recID = currentRecord.get().id;
var parameter = {
intenalId: recID
};
var purchaseorderSearchObj = search.create({
type: "purchaseorder",
filters:
[
["type","anyof","PurchOrd"],
"AND",
["applyingtransaction.type","anyof","ItemRcpt"],
"AND",
["item.type","noneof","NonInvtPart"],
"AND",
["internalidnumber","equalto",recID]
],
columns:
[
search.createColumn({
name: "itemid",
join: "item",
label: "Name"
}),
search.createColumn({
name: "inventorynumber",
join: "inventoryDetail",
label: " Number"
})
]
});
var searchResultCount = purchaseorderSearchObj.runPaged().count;
if(searchResultCount>0){
var popup = url.resolveScript({
scriptId: "customscript_an37_jj_sl_itmlistpopup",
deploymentId: "customdeploy_an37_jj_sl_itmlistpopup",
returnExternalUrl: false,
params: parameter
});
var childwindow = window.open(popup,"","width=1000,height=750");
}
else{
alert('The received items are Non-inventory items')
}
} catch (e) {
console.log(e.name,e.message);
}
}
//updated on 20-03-2019
function print_action(){
try{
var itemId_array=[];
var itemRecId_array=[];
var record = currentRecord.get();
var po_id = record.getValue({
fieldId : 'cust_po'
});
var numLines = record.getLineCount({
sublistId: 'custpage_sublst'
});
for(var j = 0; j < numLines; j++){
var selectFieldValue = record.getSublistValue({
sublistId: 'custpage_sublst',
fieldId: 'custpage_check',
line: j
});
if(selectFieldValue == true){
var itemId = record.getSublistValue({
sublistId: 'custpage_sublst',
fieldId: 'cust_itemid',
line: j
});
itemId_array.push(itemId)
var itemRecId = record.getSublistValue({
sublistId: 'custpage_sublst',
fieldId: 'cust_itemrecid',
line: j
});
itemRecId_array.push(itemRecId)
}
}
var itemId_array_encode = encodeURI(itemId_array)
var itemRecId_array_encode = encodeURI(itemRecId_array)
var labelUrl = url.resolveScript({
scriptId: "customscript_sl_raw_material_tag",
deploymentId: "customdeploy_sl_raw_material_tag",
returnExternalUrl: false,
params:{
'poId':po_id,
'itemID':itemId_array_encode,
'itemRecID':itemRecId_array_encode
}
});
var childwindow = window.open(labelUrl);
}catch(error){
console.log('error @ print_action',error)
}
}
// updated on 11/04/19 for AN-46
/**
* 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 currRec = scriptContext.currentRecord;
var sublistName = scriptContext.sublistId;
var fieldName = scriptContext.fieldId;
if(sublistName == 'item' && (fieldName == 'custcol_jj_calculate' || fieldName == 'custcol_lb_per_case_po' || fieldName == 'custcol_cases_ordered')){
var calc_check = currRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_jj_calculate'
});
if(calc_check == true){
var lb_cs = currRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_lb_per_case_po'
});
var cases_order = currRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_cases_ordered'
});
if((lb_cs == null||lb_cs == ''||lb_cs == " "||lb_cs == undefined||lb_cs == '-None-'||lb_cs == NaN ||lb_cs == 'NaN') || (cases_order == null||cases_order == ''||cases_order == " "||cases_order == undefined||cases_order == '-None-'||cases_order == NaN ||cases_order == 'NaN')){
alert('Please enter a value for Pounds/Case. Or, uncheck the checkbox to multiply cases by pounds for this item.')
}else{
tot_unit = parseFloat(cases_order)*parseFloat(lb_cs);
currRec.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: tot_unit
});
}
}
}
}catch(error){
console.log('error @ fieldChanged',error)
}
}
/**
* 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
*/
// updated on 04/04/2019 for AN-43
function sublistChanged(scriptContext) {
try{
var current_rec = scriptContext.currentRecord;
var sublist_name =scriptContext.sublistId;
var total_pound =0;
if(sublist_name == 'item'){
var numLines = current_rec.getLineCount({
sublistId: 'item'
});
for(var i=0; i<numLines; i++){
var item_internalId = current_rec.getSublistValue({
sublistId: 'item',
fieldId: 'item',
line: i
});
var unit = current_rec.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: i
});
//search for item
var itemSearchObj = search.create({
type: "item",
filters:
[
["internalidnumber","equalto",item_internalId]
],
columns:
[
search.createColumn({
name: "itemid",
sort: search.Sort.ASC,
label: "Name"
}),
search.createColumn({name: "weight", label: "Weight"}),
search.createColumn({name: "weightunit", label: "Weight Units"})
]
});
var searchResult = itemSearchObj.run().getRange({
start: 0,
end: 1
});
for (var j = 0; j<searchResult.length; j++) {
var weight = searchResult[j].getValue({
name: "weight"
});
var weight_unit = searchResult[j].getText({
name: "weightunit"
});
if(weight){
//to convert to pounds(lb)
if(weight_unit == 'kg'){
weight = parseFloat(weight) * 2.205
}
else if(weight_unit == 'g'){
weight = parseFloat(weight) / 453.592
}
else if(weight_unit == 'oz'){
weight = parseFloat(weight) / 16
}
if(total_pound == null ||total_pound == '' ||total_pound == " "||total_pound == undefined ||total_pound == '-None-'||total_pound == 0 || total_pound == '0' ||total_pound == NaN ||total_pound == 'NaN'){
total_pound = parseFloat(weight) * parseFloat(unit)
}else{
total_pound = parseFloat(total_pound) + (parseFloat(weight)* parseFloat(unit))
}
current_rec.setValue({
fieldId: 'custbody_an48_jj_estpound',
value: total_pound,
// ignoreFieldChange: true,
// fireSlavingSync: true
});
}
}
}
}
}catch(e){
console.log('error @ sublistChanged',e)
}
}
//updated on 24-04-19 for AN-49
/**
* 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) {
try{
var currentRec = scriptContext.currentRecord;
var sublistName =scriptContext.fieldId;
console.log('currentRec',currentRec)
console.log('sublistName',sublistName)
if(sublistName == 'item'){
var itemName = currentRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item'
});
console.log('itemName',itemName)
var lookupInvItems = search.lookupFields({
type: search.Type.INVENTORY_ITEM,
id: itemName,
columns: ['custitem_item_number_name_misc', 'custitem_allergens', 'custitem_standard_cost']
});
var misc = lookupInvItems.custitem_item_number_name_misc
var allergen = lookupInvItems.custitem_allergens
var stdCost = lookupInvItems.custitem_standard_cost
console.log('misc',misc)
console.log('allergen',allergen)
console.log('stdCost',stdCost)
var alertChar =null;
if(misc == false || allergen==false|| stdCost==false){
if(misc == false){
alertChar = "ITEM NUMBER, NAME, MISC. (PURCHASING)";
// alert('These checkboxes must be checked in the Item Setup: "ITEM NUMBER, NAME, MISC. (PURCHASING)". If you have questions please contact the IT Department.')
}
if(allergen == false){
if(alertChar != null){
alertChar = alertChar + ", ALLERGENS (QA)";
}else{
alertChar= "ALLERGENS (QA)";
}
// alert('These checkboxes must be checked in the Item Setup: "ALLERGENS (QA)". If you have questions please contact the IT Department.')
}
if(stdCost == false){
if(alertChar != null){
alertChar = alertChar + ", STANDARD COST (IT)";
}else{
alertChar= "STANDARD COST (IT)";
}
// alert('These checkboxes must be checked in the Item Setup: " STANDARD COST (IT)". If you have questions please contact the IT Department.')
}
console.log('alertChar',alertChar)
alert('These checkboxes must be checked in the Item Setup:'+alertChar+'. If you have questions please contact the IT Department.')
return false;
}
}
return true;
}catch(error){
console.log('error @ validateField',error)
}
}
return {
pageInit: pageInit,
rowMaterialTag: rowMaterialTag,
print_action:print_action,
sublistChanged:sublistChanged,
fieldChanged:fieldChanged,
validateField:validateField
};
});
Client Script: AN-2 CS SO Button Action
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
/**
* Script Description: This script defining the function of button
*/
/*******************************************************************************
* * AN * *
* **************************************************************************
* Date:7/11/18
* Script name: AN CS SO Btn Action
* Script id: customscript_an_cs_so_btn_action
* Deployment id: customdeploy_an_cs_so_btn_action
* Applied to: Sales order
*
* REVISION HISTORY
*
* Revision 1.0 ${02-11-2018} angel : created
* Revision 1.1 ${24-04-2019} nd : updated for AN-49
******************************************************************************/
define(['N/currentRecord','N/record','N/url','N/search'],
function(currentRecord,record,url,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) {
try {
console.log("In");
} catch (e) {
console.log(e.name,e.message);
}
}
//Fuction on Shipping Tag button click
function shippingPDF() {
try {
//console.log("shippingPDF");
var recID = currentRecord.get().id;
var parameterObj = {
intenalId: recID
};
var recObj = record.load({ type: "salesorder", id: recID });
var labelUrl = url.resolveScript({
scriptId: "customscript_sl_shipping_pdf",
deploymentId: "customdeploy_sl_shipping_pdf",
returnExternalUrl: false,
params: parameterObj
});
var childwindow = window.open(labelUrl);
} catch (e) {
console.log(e.name,e.message);
}
}
/**
* 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) {
try {
console.log("validateLine");
//to restrict item if it is not finished good
if(scriptContext.sublistId=='item'){
// console.log("validate item");
var itemClass = scriptContext.currentRecord.getCurrentSublistValue({
fieldId: "class",
sublistId: 'item'
});
console.log("itemClass",itemClass);
var clsRecordObj = record.load({ type: "classification", id: itemClass});
var parentcls=clsRecordObj.getText({
fieldId: 'parent'
});
console.log("parentcls",parentcls);
if( !( (parentcls.startsWith("Finished :")) || (parentcls=="Finished") || (itemClass=='25'))){
alert("Sorry, you have selected an item that is not a finished good. Please remove the item and try again.");
return false;
}
return true;
}
} catch (e) {
console.log(e.name,e.message);
}
}
//updated on 24-04-19 for AN-49
/**
* 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) {
try{
var currentRec = scriptContext.currentRecord;
var sublistName =scriptContext.fieldId;
console.log('currentRec',currentRec)
console.log('sublistName',sublistName)
if(sublistName == 'item'){
var itemName = currentRec.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'item'
});
console.log('itemName',itemName)
var lookupInvItems = search.lookupFields({
type: search.Type.ASSEMBLY_ITEM,
id: itemName,
columns: ['custitem_item_number_name_misc', 'custitem_allergens', 'custitem_standard_cost','custitem_routings','custitem_bom']
});
var bom = lookupInvItems.custitem_bom
var routing = lookupInvItems.custitem_routings
var misc = lookupInvItems.custitem_item_number_name_misc
var allergen = lookupInvItems.custitem_allergens
var stdCost = lookupInvItems.custitem_standard_cost
console.log('bom',bom)
console.log('routing',routing)
console.log('misc',misc)
console.log('allergen',allergen)
console.log('stdCost',stdCost)
var alertChar =null;
if(misc == false || allergen==false|| stdCost==false || routing == false || bom==false ){
if(misc == false){
alertChar = "ITEM NUMBER, NAME, MISC. (PURCHASING)";
// alert('These checkboxes must be checked in the Item Setup: "ITEM NUMBER, NAME, MISC. (PURCHASING)". If you have questions please contact the IT Department.')
}
if(allergen == false){
if(alertChar != null){
alertChar = alertChar + ", ALLERGENS (QA)";
}else{
alertChar= "ALLERGENS (QA)";
}
// alert('These checkboxes must be checked in the Item Setup: "ALLERGENS (QA)". If you have questions please contact the IT Department.')
}
if(stdCost == false){
if(alertChar != null){
alertChar = alertChar + ", STANDARD COST (IT)";
}else{
alertChar= "STANDARD COST (IT)";
}
// alert('These checkboxes must be checked in the Item Setup: " STANDARD COST (IT)". If you have questions please contact the IT Department.')
}
if(routing == false){
if(alertChar != null){
alertChar = alertChar + ", ROUTINGS (PRODUCTION)";
}else{
alertChar= "ROUTINGS (PRODUCTION)";
}
// alert('These checkboxes must be checked in the Item Setup: "ALLERGENS (QA)". If you have questions please contact the IT Department.')
}
if(bom == false){
if(alertChar != null){
alertChar = alertChar + ", BOM (R&D/PURCHASING)";
}else{
alertChar= " BOM (R&D/PURCHASING)";
}
// alert('These checkboxes must be checked in the Item Setup: "ALLERGENS (QA)". If you have questions please contact the IT Department.')
}
console.log('alertChar',alertChar)
alert('These checkboxes must be checked in the Item Setup:'+alertChar+'. If you have questions please contact the IT Department.')
return false;
}
}
return true;
}catch(error){
console.log('error @ validateField',error)
}
}
return {
pageInit: pageInit,
shippingPDF:shippingPDF,
validateLine: validateLine,
validateField:validateField
};
});