Sim Greenbaum
11/19/2020, 8:29 PM/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/ui/dialog'], function (dialog) {
function saveRecord(context) {
var record = context.currentRecord;
var Usamazonsku = record.getValue({ fieldId: 'custitem3'});
var Caamazonsku = record.getValue({ fieldId: 'custitem9' });
var amazonFlag = record.getValue({ fieldId: 'custitem_fa_amz_fba01'});
var amazonFlag2 = record.getValue({ fieldId: 'custitem_fa_amz_fba02'});
var conditions = [
Usamazonsku != null && amazonFlag === false,
Caamazonsku != null && amazonFlag2 === false,
Usamazonsku === null && amazonFlag === true,
Caamazonsku === null && amazonFlag2 === true
]
console.log(!conditions.includes(false))
if (conditions.includes(true)){
console.log("I am watching")
var options = {
title: 'Error',
message: 'All Amazon fields have not been filed out correctly !!'
};
dialog.alert(options);
return false
}
else{
return true
}
}
return {
saveRecord: saveRecord
};
})
battk
11/19/2020, 8:33 PMbattk
11/19/2020, 8:33 PMSim Greenbaum
11/19/2020, 8:33 PMSandii
11/19/2020, 8:34 PM.includes()
is in ECMA5?Sandii
11/19/2020, 8:34 PM.indexOf(true) > -1
maybe?battk
11/19/2020, 8:36 PMbattk
11/19/2020, 8:36 PMnot includes false
is not the same as includes true
battk
11/19/2020, 8:37 PMSim Greenbaum
11/19/2020, 8:44 PMSandii
11/19/2020, 8:45 PMSandii
11/19/2020, 8:45 PMSim Greenbaum
11/19/2020, 8:46 PMSandii
11/19/2020, 8:46 PMincludes()
is working, or its a flaw in the logic as battk suggested, I am not includes()
is supported in the version of ECMASim Greenbaum
11/19/2020, 8:47 PMbattk
11/19/2020, 8:48 PMbattk
11/19/2020, 8:48 PMbattk
11/19/2020, 8:49 PMbattk
11/19/2020, 8:49 PMbattk
11/19/2020, 8:50 PMSandii
11/19/2020, 8:51 PMSim Greenbaum
11/19/2020, 9:08 PMSim Greenbaum
11/19/2020, 9:08 PMbattk
11/19/2020, 9:10 PMSim Greenbaum
11/19/2020, 9:12 PMbattk
11/19/2020, 9:14 PM!Usamazonsku && amazonFlag
battk
11/19/2020, 9:14 PMjen
11/20/2020, 5:13 PMjen
11/20/2020, 5:13 PM/**
* md_integrity_ss2.js
* @ssScriptName ModuleIntegrity
* @ssScriptId md_integrity
* @ssApiVersion 2.0
*
* last modified 2020-06-23 JB
*/
define(function() {
/* Define the functions in this module. */
// Returns true if the passed in thing has a value, false if blank, null, undefined, empty, or ‘To Be Generated’.
// We can override whether or not to include blank, undefined, empty, or ‘To Be Generated’ as null.
function hasValue(value_to_check, options) {
// Set up some default options.
if(options === undefined) {
options = {
check_to_be_generated: true,
check_blank: true,
check_undefined: true,
check_empty_array: true,
check_is_nan: false
}
}
if(options.check_to_be_generated === undefined)
options.check_to_be_generated = true;
if(options.check_blank === undefined)
options.check_blank = true;
if(options.check_undefined === undefined)
options.check_undefined = true;
if(options.check_empty_array === undefined)
options.check_empty_array = true;
if(options.check_is_nan === undefined)
options.check_is_nan = false;
// Check if the passed-in-value has a value!
if(value_to_check === null)
return false;
if(options.check_blank && value_to_check === ‘’)
return false;
if(options.check_undefined && value_to_check === undefined)
return false;
if(options.check_to_be_generated && value_to_check == ‘To Be Generated’)
return false;
if(options.check_empty_array && typeof value_to_check !== ‘string’ && value_to_check.length == 0)
return false;
if(options.check_is_nan && isNaN(value_to_check))
return false;
// At this point it passed all the checks so return true.
return true;
}
// If the supplied value is an empty string, return null instead. Useful for
// adding values to a sublist, which doesn’t seem to accept blank strings.
function nullIfEmpty(value) {
if(value == ‘’)
return null;
else
return value;
}
/* Return the names of the functions. Note that these can be different from the
* actual names above, but for clarity let’s keep them the same.
*/
return {
hasValue: hasValue,
nullIfEmpty: nullIfEmpty
}
});
jen
11/20/2020, 5:14 PMif(md_integrity.hasValue(thing))