This topic contains 4 replies, has 0 voices, and was last updated by dmashburn3 8 years, 4 months ago.
-
AuthorPosts
-
June 27, 2016 at 7:53 am #6371
dmashburn3Hi,
This is my first real script and I’m getting this error. I ran it through the console and had no problems with it, however it tosses this error when I upload it and try to create a sales order.
The error occurs in line 4 of this code on the demand[j].rawValues[0].value .
Code:
function makeComparisons(itemList, itemQuantity, demand, supply){
for ( var i = 0; itemList != null && i 0){
itemQuantity[i] = (parseInt(itemQuantity[i]) – parseInt(demand[j].rawValues[2].value));
}
}
}}
}
The entire code looks like this:Code:
function beforeSubmit(type){
if(type == ‘create’ || type == ‘edit’){
setExpShip();
}
function setExpShip(){
var iL = getListOfItems();
var iQ = getQtyOfItems();
var d = getDemand(iL);
var s = getSupply(iL);
makeComparisons(iL,iQ,d,s);
}
function getListOfItems() {
var itemList = [];
for ( var i = 1; i 0){
itemQuantity[i] = (parseInt(itemQuantity[i]) – parseInt(demand[j].rawValues[2].value));
}
}
}}
}
for (var k = 0; itemList != null && k This is a cached copy. Click here to see the original post. -
June 27, 2016 at 9:37 am #6372
dmashburn3Going back to one of my previous posts, I forgot that someone told me that using getValue is a better idea than the column syntax.
So I’ve replace it all as follows and it allows the save of the record, however now I’m getting an error on the function dateFormat.
I’m just going to keep troubleshooting this in my own post and hopefully it’ll be helpful to someone else down the line.
Code:
function beforeSubmit(type){
if(type == ‘create’ || type == ‘edit’){
setExpShip();
}
function setExpShip(){
var iL = getListOfItems();
var iQ = getQtyOfItems();
var d = getDemand(iL);
var s = getSupply(iL);
makeComparisons(iL,iQ,d,s);
}
function getListOfItems() {
var itemList = [];
for ( var i = 1; i <= nlapiGetLineItemCount(‘item’); i++) {
itemList.push(nlapiGetLineItemValue(‘item’, ‘item’, i));
}
return itemList;
}
function getQtyOfItems() {
var itemQuantity = [];
for ( var i = 1; i <= nlapiGetLineItemCount(‘item’);i++){
itemQuantity.push(nlapiGetLineItemValue(‘item’,’quantity’,i));
}
return itemQuantity;
}
function getDemand(itemList) {
var demandFilters = [];
demandFilters.push( new nlobjSearchFilter(‘item’, null, ‘anyof’, itemList));
var demand = nlapiSearchRecord(‘transaction’,1112,demandFilters);
return demand;
}
function getSupply(itemList) {
var supplyFilters = [];
supplyFilters.push( new nlobjSearchFilter(‘item’,null,’anyof’,itemList));
var supply = nlapiSearchRecord(‘transaction’,1114,supplyFilters);
return supply;
}
function makeComparisons(itemList, itemQuantity, demand, supply){
for ( var i = 0; itemList != null && i < itemList.length; i++){
for (var j = 0; demand != null && j < demand.length; j++){
if (itemList[i] == demand[j].getValue(‘item’,null,’group’)){
if( parseInt(itemQuantity[i]) <= parseInt(demand[j].getValue(‘locationquantityavailable’,’item’,’group’)) && demand[j].getValue(‘locationquantityavailable’,’item’,’group’) != “”){
var today = nlapiGetFieldValue(‘trandate’);
var dateToSet = stringtodate(modifyDateByDays(today,3));
nlapiSelectLineItem(‘item’,parseInt(j)+1);
nlapiSetCurrentLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,dateToSet.dateFormat(‘m/d/y’));
} else {
if(demand[j].getValue(‘locationquantityavailable’,’item’,’group’) > 0){
itemQuantity[i] = (parseInt(itemQuantity[i]) – parseInt(demand[j].getValue(‘locationquantityavailable’,’item’,’group’)));
}
}
}}
}
for (var k = 0; itemList != null && k < itemList.length; k++){
for (var m = 0; supply != null && m < supply.length; m++){
if( itemList[k] == supply[m].getValue(‘item’,null,’group’)){
if ( supply[m].getValue(‘locationquantitybackordered’,null,’group’) != “”){
var emptyDate = nlapiGetLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,parseInt(k)+1);
if (emptyDate == “”){
if( (parseInt(itemQuantity[k]) + parseInt(supply[m].getValue(‘locationquantitybackordered’,null,’group’)) <= parseInt(supply[m].getValue(‘formulanumeric’,null,’sum’)))){
var expShipDate = nlapiStringToDate(supply[m].getValue(‘custcol_exp_rec_date’,null,’group’));
if (expShipDate != “” && expShipDate != null){
nlapiSelectLineItem(‘item’,parseInt(k)+1);
nlapiSetCurrentLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,expShipDate.dateFormat(‘m/d/y’));
} else {
nlapiSelectLineItem(‘item’,parseInt(k)+1);
nlapiSetCurrentLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,’01/01/1900′);
}
} else {
itemQuantity[k] = parseInt(itemQuantity[k]) – parseInt(supply[m].getValue(‘formulanumeric’,null,’sum’));
supply[m].getValue(‘locationquantitybackordered’,’item’,’group’) = Math.max(0,parseInt(supply[m].getValue(‘locationquantitybackordered’,’item’,’group’)) – parseInt(supply[m].getValue(‘locationquantitybackordered’,’item’,’group’)));
}
}
} else {
var emptyDate = nlapiGetLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,parseInt(k)+1);
if (emptyDate == “”){
supply[m].getValue(‘locationquantitybackordered’,null,’group’) = 0;
if( (parseInt(itemQuantity[k]) + parseInt(supply[m].getValue(‘locationquantitybackordered’,’item’,’group’)) <= parseInt(supply[m].getValue(‘formulanumeric’,’item’,’sum’)))){
var expShipDate = nlapiStringToDate(supply[m].getValue(‘custcol_exp_rec_date’,null,’group’));
if (expShipDate != “” && expShipDate != null){
nlapiSelectLineItem(‘item’,parseInt(k)+1);
nlapiSetCurrentLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,expShipDate.dateFormat(‘m/d/y’),(parseInt(k)+1));
} else {
nlapiSelectLineItem(‘item’,parseInt(k)+1);
nlapiSetCurrentLineItemValue(‘item’,’custcol_expect_ship_date_so_line’,’01/01/1900′);
}
} else {
itemQuantity[k] = parseInt(itemQuantity[k]) – parseInt(supply[m].getValue(‘formulanumeric’,null,’sum’));
supply[m].getValue(‘locationquantitybackordered’,’item’,’group’) = Math.max(0,parseInt(supply[m].getValue(‘locationquantitybackordered’,’item’,’group’)) – parseInt(supply[m].getValue(‘locationquantitybackordered’,’item’,’group’)));
}
}
}
}
}
}
}
function modifyDateByDays(date, days) {
if (!date.getDate) {
date = nlapiStringToDate(date);
}
var newDate = new Date(date);
newDate.setDate(newDate.getDate() + parseInt(days));
var dateString = nlapiDateToString(newDate);
return dateString;
}
}
โ -
June 30, 2016 at 2:29 am #6373
NelliottWhere did you see that “dateFormat”was a method you could use on a NetSuite DateObject?
I only ask because I don’t believe it is… but the documentation is so out of date and unreliable that I may be wrong!
Go to the help system and search on Date APIs.
Normally you supply the format at the time you convert a string to the dateObject such :
nlapiStringToDate(str, format)
Also you don’t need a function to add days either since the API can do that neatly for you
nlapiAddDays(d, days)
-
June 30, 2016 at 7:24 am #6374
dmashburn3Hi Nelliott,
Yes, dateFormat was not working. Here is the final script that I actually got to work though! Just working out some tiny bugs here and there that pop up along the way.
Code:
function beforeSubmit(type){
if(type == ‘create’ || type == ‘edit’){
setExpShip();
}
function setExpShip(){
var iL = getListOfItems();
var iQ = getQtyOfItems();
var lT = getLtOfItems(iL);
var d = getDemand(iL);
var s = getSupply(iL);
var a = getAvailability(iL);
makeComparisons(iL,iQ,d,s,lT,a);
}
function getListOfItems() {
var itemList = [];
for ( var i = 1; i <= nlapiGetLineItemCount('item'); i++) {
itemList.push(nlapiGetLineItemValue('item', 'item', i));
}
return itemList;
}
function getQtyOfItems() {
var itemQuantity = [];
for ( var i = 1; i <= nlapiGetLineItemCount('item');i++){
itemQuantity.push(nlapiGetLineItemValue('item','quantity',i));
}
return itemQuantity;
}
function getLtOfItems(itemList){
var leadTimeFilters = [];
leadTimeFilters.push( new nlobjSearchFilter('internalid', null,'anyof',itemList));
var leadTime = nlapiSearchRecord('item',1116,leadTimeFilters);
return leadTime;
}
function getDemand(itemList) {
var demandFilters = [];
demandFilters.push( new nlobjSearchFilter('item', null, 'anyof', itemList));
var demand = nlapiSearchRecord('transaction',1112,demandFilters);
return demand;
}
function getSupply(itemList) {
var supplyFilters = [];
supplyFilters.push( new nlobjSearchFilter('item',null,'anyof',itemList));
var supply = nlapiSearchRecord('transaction',1114,supplyFilters);
return supply;
}
function modifyDateByDays(date, days) {
if (!date.getDate) {
date = nlapiStringToDate(date);
}
var newDate = new Date(date);
newDate.setDate(newDate.getDate() + parseInt(days));
var dateString = nlapiDateToString(newDate);
return dateString;
}
function getAvailability(itemList){
var avail = [];
for ( var z = 0; z < itemList.length; z++){
avail[z] = (nlapiGetLineItemValue('item','quantityavailable',parseInt(z)+1));
}
return avail;
}
function makeComparisons(itemList,itemQuantity,demand,supply,leadTime,avail){
var checkDate = [];
for ( var i = 0; itemList != null && i < itemList.length; i++){
checkDate[i] = nlapiGetLineItemValue('item','custcol_expect_ship_date_so_line',parseInt(i)+1);
}
for ( var i = 0; itemList != null && i < itemList.length; i++){
if (checkDate[i] == null || checkDate[i] == ""){
if (nlapiGetLineItemValue('item','costestimatetype',parseInt(i)+1) != "ITEMDEFINED"){
if (parseInt(itemQuantity[i]) <= parseInt(avail[i])){
var today = nlapiGetFieldValue('trandate');
var dateToSet = modifyDateByDays(today,1);
nlapiSelectLineItem('item',parseInt(i)+1);
nlapiSetCurrentLineItemValue('item','custcol_expect_ship_date_so_line',dateToSet);
nlapiCommitLineItem('item');
} else {
if (avail[i] != "" && avail[i] != "0" && avail[i] != null){
itemQuantity[i] = (parseInt(itemQuantity[i]) – parseInt(avail[i]));
}
}
}
}
}
var supplyItem = [];
var supplyPoQty = [];
var supplyBoQty = [];
var supplyExpRecDate = [];for (var f = 0; supply != null && f < supply.length; f++){
supplyItem.push(supply[f].getValue('item',null,'group'));
}
for (var g = 0; supply != null && g <supply.length; g++){
supplyPoQty.push(supply[g].getValue('formulanumeric',null,'sum'));
}
for (var h = 0; supply != null && h < supply.length; h++){
supplyBoQty.push(supply[h].getValue('locationquantitybackordered','item','group'));
}
for (var p = 0; supply != null && p < supply.length; p++){
supplyExpRecDate.push(supply[p].getValue('custcol_exp_rec_date',null,'group'));
}
for ( var a = 0; itemList != null && a < itemList.length; a++){
for ( var b = 0; supplyItem != null && b < supplyItem.length; b++){
var checkDate = [];
for ( var i = 0; itemList != null && i < itemList.length; i++){
checkDate[i] = nlapiGetLineItemValue('item','custcol_expect_ship_date_so_line',parseInt(i)+1);
}
if (checkDate[a] == null || checkDate[a] == ""){
if (nlapiGetLineItemValue('item','costestimatetype',parseInt(i)+1) != "ITEMDEFINED"){
if (itemList[a] == supplyItem[b]){
if( (parseInt(itemQuantity[a]) + parseInt(supplyBoQty[b])) <= parseInt(supplyPoQty[b])){
var shipDate = supplyExpRecDate[b];
if(shipDate != "" || shipDate != null){
var shipDate2 = modifyDateByDays(shipDate,3)
nlapiSelectLineItem('item',parseInt(a)+1);
nlapiSetCurrentLineItemValue('item','custcol_expect_ship_date_so_line',shipDate2);
nlapiCommitLineItem('item');
} else {
var lT = parseInt(leadTime[a]);
var today = nlapiGetFieldValue('trandate');
var dateToSet = modifyDateByDays(today,lT);
nlapiSelectLineItem('item',parseInt(a)+1);
nlapiSetCurrentLineItemValue('item','custcol_expect_ship_date_so_line',dateToSet);
nlapiCommitLineItem('item');
}
} else {
if (supplyBoQty[b] != "" || supplyBoQty != null){
supplyBoQty[b] = (supplyBoQty[b] – supplyPoQty[b]);
}
}
}
}
}
}
}
debugger;
for ( var a = 0; itemList != null && a < itemList.length; a++){
var checkDate = [];
for ( var i = 0; itemList != null && i < itemList.length; i++){
checkDate[i] = nlapiGetLineItemValue('item','custcol_expect_ship_date_so_line',parseInt(i)+1);
}
if (checkDate[a] == null || checkDate[a] == ""){
if (nlapiGetLineItemValue('item','costestimatetype',parseInt(a)+1) != "ITEMDEFINED"){
var lT = parseInt(leadTime[a].getValue('leadtime',null,'max'));
var today = nlapiGetFieldValue('trandate');
var dateToSet = modifyDateByDays(today,lT);
nlapiSelectLineItem('item',parseInt(a)+1);
nlapiSetCurrentLineItemValue('item','custcol_expect_ship_date_so_line',dateToSet);
nlapiCommitLineItem('item');
}
}
}
}
} -
June 30, 2016 at 7:29 am #6375
dmashburn3I probably took the long route in a number of ways, but it is functioning at this point which is a good start. I plan on returning to it to rewrite and try to condense it.
-
AuthorPosts
You must be logged in to reply to this topic.