I am facing a weird problem where my code (specifically a record.save action) does not seem to be executed. The code is located in the 'reduce' phase of a suitescript 2.0 map/reduce script.
I have no clue what the cause for this might be. The logging does display 'is this executed' as stated in the example below but the lines below that do not seem to be executed. The logging does not show 'Order lines marked for order with ID:
//load the order
var SOrecord = record.load({
type: record.Type.SALES_ORDER,
id: orderId,
isDynamic: false
});
setLineValues(SOrecord, values, newShipmentId)
log.debug('Is this executed?');
//Save Order
var recId = SOrecord.save({enableSourcing: false, ignoreMandatoryFields: true});
log.debug('Order lines marked for order with ID: ', recId)
return recId;
Can anyone help?
UPDATE
//load the order
var SOrecord = record.load({
type: record.Type.SALES_ORDER,
id: orderId,
isDynamic: false
});
log.debug('Order Loaded! ', SOrecord);
//Loop lines present in values array
for(var i = 0; i < values.length; i++){
//Generate Shipment Line ID, 3 digits starting at 001
var tmpShipmentLineId = i + 1
var shipmentLineId = tmpShipmentLineId.toString().padStart(3, '0');
log.debug('Shipment Line ID: ', shipmentLineId)
//check if first fulfillment is done, if yes mark ready for second fulfillment
if(SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) == true){
log.debug('Line: ' + i, 'Mark ready for 2nd fulfillment')
//Set values
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_send_to_ff_2nd',
line: Number(values[i]),
value: true
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_id_2nd',
line: Number(values[i]),
value: newShipmentId
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_line_id_2nd',
line: Number(values[i]),
value: shipmentLineId
});
}
//If not, mark ready for first fulfillment
else{
log.debug('Line: ' + i, 'Mark ready for first fulfillment')
//Set Values
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_il_send_ff_interface',
line: Number(values[i]),
value: true
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_id',
line: Number(values[i]),
value: shipmentId
});
SOrecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcol_shipment_line_id',
line: Number(values[i]),
value: shipmentLineId
});
}
};
log.debug('SOrecord after changes: ', SOrecord);
SOrecord.save();
log.debug('Record Saved ', 'END');
Above you'll find an extended code snippet, for some reason all code outside of the for loop does not seem to be executed... Any ideas?
I'm not sure I understand the setup of the code here... the text refers to the first code snippet but the second one seems more informative. Here are some general things I would try but if you clarify what is printing and what is not on the second code snippet maybe I can help more...
(1) Add a try catch for better error handling. You seem to be getting a error that's not being logged.
(2) Try loading the record in dynamic mode and using selectLine -> setCurrentSublistValue -> commitLine
(3) it seems you are using "line: values:[i]" I don't have a example of what that returns but it seems it should be "line: i"
(4) have you logged this - SOrecord.getSublistValue({sublistId: 'item', fieldId: 'custcol_il_send_ff_interface', line: values[i]}) - if not please do and let us know what the value is...
Related
I have a suitelet that is creating an order. Most times this works but sometimes, maybe 1 in 50 it fails with this error. "Please enter a value for amount."
The error is thrown when sommitting this.
if(orderLine.amount){
log.debug("itemrate", orderLine.itemrate);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'rate',
value : Number(orderLine.itemrate ? orderLine.itemrate : (orderLine.amount / orderLine.qty))
});
fieldServices.sleep(1000);
log.debug("Amount", orderLine.amount);
salesOrder.setCurrentSublistValue({
sublistId : 'item',
fieldId : 'amount',
value : Number(orderLine.amount)
});
}
The logs on a fail execution reads
2 View Debug Amount 26/05/2020 11:21 AM -System- 118.0909090909091
3 View Debug itemrate 26/05/2020 11:21 AM -System- 118.0909
So the amount is getting set with an amount but when I try to commit the line it doesn't work 100% of the time.
So here was the problem. I assumed the logging was on the line that I posted but it turned out it was trying to add another line with the amount of 0. JavaScript being JavaScript saw 0 as false in
if(orderLine.amount)
so the amount was never added to the line. I changed this if statement to read
if(orderLine.amount || orderLine.amount == 0)
This solved the problem.
I am trying to copy all the line items in the item sublist in one sales order to another new sales order. I am getting all the line items and while setting the line items I have followed the order shown below:
Price level
Item
Quantity
Amount
Tax Code
The issue is that all the values are set correctly but the amount and tax code fields are not set. Is this the correct order to set the line item fields? If not, what is the order that I should follow so that lines commit successfully?
var set=currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value:salesOrd_item[j]
});
alert('item is being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value:salesOrd_quantity[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'units',
value:salesOrd_units[j]
});
alert('units are being set');
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value:salesOrd_taxcode[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
value:salesOrd_pricelevel[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'rate',
value:salesOrd_rate[j]
});
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value:salesOrd_amount,
});
One thing to consider is that the Rate (and therefore Amount) are dependant on the Price Level. You cannot set a Price Level and then also set a custom Rate that is different than the Price Level, NetSuite will not allow this in the UI or via SuiteScript. If you're trying to copy a line from another order just copy in the Price Level and Quantity, the Rate and Amount will auto update.
This leads to a second consideration. When you fill a field in on a line, often times other fields are slaved to that field. This happens asynchronously, so if you fill in a slaved field before it gets updated by NetSuite, your value will be overwritten. This might be happening to your tax field. To avoid this, NetSuite added a property called fireSlavingSync to ensure that each setValue on a line waits till all slaved actions have completed before executing your next line of code. Try editing your lines to add this extra parameter like this:
currentRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value:salesOrd_item[j],
fireSlavingSync: true
});
I would like to copy a few lines of the sales order "item" sublist and insert them into another sales order.
For now I have just found N/record.insertLine(sublistId, lineNr, ignoreRecalc), but I can't see how this function could help me because it doesn't take any data.
My use case is that I have a sales order out of which I have to generate other sales orders, but only containing some of the items of the original sales order.
I think you need these two to work with.
Get Sublist
...
var objField = objRecord.getSublistField({
sublistId: 'item',
fieldId: 'item',
line: 3
});
Set Sublist
objRecord.setSublistValue({
sublistId: 'item',
fieldId: 'item',
line: 3,
value: true
});
I'm using select2 for tagging and I have it setup such that a user can add new tags as well. The issue that I'm dealing with is validating the user entry and adding the sanitized tag to selection.
To be more specific, when a user enters a space in a tag, i use formatNoMatches to display a js link to sanitize the tag and then add the tag programmatically. This code seems to run without errors but when sanitize is called all selections of the input are cleared.
Any clues where i might be going wrong?
var data=[{id:0,tag:'enhancement'},{id:1,tag:'bug'},{id:2,tag:'duplicate'},{id:3,tag:'invalid'},{id:4,tag:'wontfix'}];
function format(item) { return item.tag; }
function sanitize(a){
$("#select").select2('val',[{
id: -1,
tag: a
}]);
console.log(a);
};
$("#select").select2({
tags: true,
// tokenSeparators: [",", " "],
createSearchChoice: function(term, data) {
return term.indexOf(' ') >= 0 ? null :
{
id: term,
tag: term
};
},
multiple: true,
data:{ results: data, text: function(item) { return item.tag; } }, formatSelection: format, formatResult: format,
formatNoMatches: function(term) { return "\"" + term + "\" <b>Is Invalid.</b> <a onclick=\"sanitize('"+ term +"')\">Clear Invalid Charecters</a>" }
});
Only this solution works for me:
function convertObjectToSelectOptions(obj){
var htmlTags = '';
for (var tag in obj){
htmlTags += '<option value="'+tag+'" selected="selected">'+obj[tag]+'</option>';
}
return htmlTags;
}
var tags = {'1':'dynamic tag 1', '2':'dynamic tag 2'}; //merge with old if you need
$('#my-select2').html(convertObjectToSelectOptions(tags)).trigger('change');
After hacking on it some more i realized that I should be setting the new item to the "data" property and not value.
var newList = $.merge( $('#select').select2('data'), [{
id: -1,
tag: a
}]);
$("#select").select2('data', newList)
You can set new value (if tags you can pass array) and trigger 'change' event.
var field = $('SOME_SELECTOR');
field.val(['a1', 'a2', 'a3']) // maybe you need merge here
field.trigger('change')
About events: https://select2.github.io/options.html#events
I am trying to find out why the filter function isn't working, but I am stucked. This is the first time I am using Dojo but I am not really familliar with that framework. I am trying and searching for maybe 2 or 3 hours but I can't find a solution.
Waht I want, is to implement a filter or search mechanism. But it is not working, yet...
This is my code:
dojo.require('dojo.store.JsonRest');
dojo.require('dijit.layout.ContentPane');
dojo.require("dijit.form.Button");
dojo.require('dojox.grid.DataGrid');
dojo.require('dojo.data.ObjectStore');
dojo.require('dijit.form.TextBox');
dojo.require('dojox.data.AndOrReadStore');
dojo.require('dojo._base.xhr');
dojo.require('dojo.json')
dojo.require('dojo.domReady');
dojo.ready(
function(){
var appLayout = new dijit.layout.ContentPane({
id: "appLayout"
}, "appLayout");
var textBox = new dijit.form.TextBox({
name: "searchbox",
placeHolder: "Search ..."
});
var filterButton = new dijit.form.Button({
label: 'Filter',
onClick: function () {
searchWord = textBox.get('value');
query = "id: '"+searchWord
+"' OR date_A: '"+searchWord
+"' OR dateB: '"+searchWord
+"' OR product: '"+searchword+"'";
grid.filter({complexQuery: query}, true);
}
});
store = new dojo.store.JsonRest({target:'products/'});
grid = new dojox.grid.DataGrid(
{
store:dojo.data.ObjectStore({objectStore: store}),
structure:
[
{name:'id', field: 'id'},
{name:'date_A', field: 'dateA'},
{name:'date_B', field: 'dateB'},
{name:'product' , field: 'product'},
],
queryOptions: {ignoreCase: true}
});
textBox.placeAt(appLayout.domNode);
filterButton.placeAt(appLayout.domNode);
grid.placeAt(appLayout.domNode);
appLayout.startup();
}
);
Would be very nice if u can tell me what's wrong with this dojo code...
The result is, that the loading icon appears and after a while the unfiltered data is shown... There is no exception thrown.
Thanks in advance.
Ok, I have solved it with the AndOrReadWriteStore. You can also use an AndOrReadStore. The problem was, that the JSON data wasn't in the right format. You can see the right format here: dojotoolkit.org/api/dojox/data/AndOrReadStore. The other change is: I used the url instead the data attribute inside the store. So finally it is working now. Thx anyway.
Here's an example of a filter that uses both an AND and an OR:
grid.filter("(genre: 'Horror' && (fname: '" + searchWord + "' || lname:'" + searchWord + "'))")
So the users search word is filtered across fname and lname as an OR but it also searches for genre = Horror as an AND.
This document has other examples...
http://livedocs.dojotoolkit.org/dojox/data/AndOrReadStore