Setting the tax code on a Sales Order Item in SuiteScript 2.0 - suitescript2.0

I have created a script to add a Finance Charge item to my sales orders when they are edited but can't get it to set the tax Code. Also the line is not committing (because of the tax code issue?)
I have tried Internal IDs and names but am stuck
Any help?
define(['N/currentRecord'],
function(currentRecord) {
function AddFinanceCharge() {
try {
var record = currentRecord.get();
record.selectNewLine({ //add a line to a sublist
sublistId: 'item' //specify which sublist
});
record.setCurrentSublistValue({ //set item field
sublistId: 'item',
fieldId: 'item',
value: 1003 //replace with item internal id
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: 1 //replace with quantity
});
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxCode',
value: 'VAT:S-GB'
});
record.commitLine({ //writes the line entry into the loaded record
sublistId: 'item'
});
log.debug ({
title: 'Success',
details: 'Alert displayed successfully'
});
} catch (e) {
log.error ({
title: e.name,
details: e.message
});
}
}
return {
pageInit: AddFinanceCharge
};
});

If you only use Tax codes, not Tax Groups I believe you can create a search to find internal ids:
var taxitemSearchObj = search.create({
type: "salestaxitem",
columns: ["internalid", "country", "rate"],
filters: [['firstFilter', 'firstComparisonOperator', firstValue]], 'and', ['anotherFilter', 'anotherComparisonOperator', anotherValue]] // i.e. ['itemid', 'is' 'VAT:S-GB'],
});
You can find available search filters in the NS record browser-
here (2019.2 version)
'VAT:S-GB' might be itemid? Then:
var taxCodeInternalId = taxitemSearchObj.run().getRange(0,1)[0].id // If you know there is only 1 code matching the search query
record.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode', // FYI I'm not sure if capitalization matters here but I downcased the capital C
value: taxCodeInternalId
});
**Disclaimer - Does NOT work with mixed tax code / tax groups. To get that you'll need to make the search dynamic ('taxgroup' or 'salestaxitem'). Unfortunately Netsuite will overwrite your taxcode internal ID if "ENABLE TAX LOOKUP ON SALES AND PURCHASES" is selected in your tax preferences (Setup > Accounting > Tax Setup - set per nexus). If this option is not selected you'll need to make sure to set a tax code on every line item.

you have to pass internal id of the tax code if you re using setValue, use SetText instead of setValue and check.

Related

Looping Through a Group in Suitescript 2.0

I am passing sales orders grouped by item into a function. I need to load the sales orders to modify the sales order record that it has already been processed. How would I go about getting all sales orders grouped under the item?
var itemId = result.getValue({
name: 'item',
summary: 'GROUP'
});
The above code gets me the item id for what the orders in the given result are being grouped by. There could be any number of sales within a single group.
Running a grouped saved search in SuiteScript doesn't give you the ability to "drill down" like you can when running a similar search in the user interface. As soon as you have a summary criteria for any column in a saved search, Netsuite requires that all your columns be summarized. If you want to get the internal IDs for the Sales Orders, then they will have to be returned as a summarized column in your saved search code.
Something like this:
const searchObj = search.create({
type: search.Type.SALES_ORDER,
filters: [
['mainline', 'is', 'F']
//,'AND', any other filters you need...
],
columns: [
search.createColumn({
name: "item",
summary: "GROUP"
}),
search.createColumn({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
})
]
}).run().each(function(result) {
const itemId = result.getValue({name: "item", summary: "GROUP"})
const salesOrderIds = result.getValue({
name: "formula(text)",
summary: "MAX",
formula: "ns_concat({internalid})"
}).split(',')
return true
})

PivotTable.JS Callback implementation problem

I have implemented PivotTable.JS in Filemaker and it works great. I've added the callback code and that function seems to be working when I click on a cell. When click on the cell I get the dialog "Message from webpage", I assume I still need to add some code to show the records that makes up the content of the click cell. What would be the approach to show the records, unfortunately I am not java script savvy.
$("#output").pivotUI(
$.pivotUtilities.tipsData, {
cols: ["Quarter Latest"],
rows: ["Customer"],
vals: ["Wt Forecast"],
aggregatorName: "Sum",
rendererName: "Table",
renderers: $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.export_renderers
),
rendererOptions: {
table: {
clickCallback: function(e, value, filters, pivotData){
var names = [];
pivotData.forEachMatchingRecord(filters,
function(record){ names.push(record.Name); });
alert(names.join("\n"));
}
}
}
});
I guess the problem is that you are pushing into the array 'names' a field 'Name' that is not available in your recordset.
You can access de complete json returned on the clickCallBack by making a small change to your code.
$("#output").pivotUI(
$.pivotUtilities.tipsData, {
cols: ["Quarter Latest"],
rows: ["Customer"],
vals: ["Wt Forecast"],
aggregatorName: "Sum",
rendererName: "Table",
renderers: $.extend(
$.pivotUtilities.renderers,
$.pivotUtilities.c3_renderers,
$.pivotUtilities.export_renderers
),
rendererOptions: {
table: {
clickCallback: function(e, value, filters, pivotData){
var fullData = [];
pivotData.forEachMatchingRecord(filters,
function(record){ fullData.push(record); });
console.log(fullData);
}
}
}
});
Perhaps you can later pass that JSON to another function and build a table.

bigcommerce single page checkout not working in checkout sdk

hello every one i am new in big commerce.
Now i am updating single page checkout using checkout sdk. every thing work fine till now i am following git hub implementing instructions . But the the problem is after update customer shipping address need to select the shipping option for shipping. I am using this syntax for doing this
const saddress = {
address1: $('#shippingaddress').val(),
address2: "",
city: $('#shippingcity').val(),
company: "",
country: $('#shippingcountry').val(),
countryCode: "AU",
customFields: [],
email: $('#email').val(),
firstName: $('#shippingfname').val(),
lastName:$('#shippinglname').val(),
phone: $('#shippingphone').val(),
postalCode: $('#shippingzip').val(),
stateOrProvince: $('#shippingProvince').val(),
stateOrProvinceCode: $('#shippingProvince').val(),
};
const updateaddress = await
service.updateShippingAddress(saddress);
After complete this action the function return all shipping address details along with the ID column and shipping options available in this address. but the problem is that function return the options and also the shipping address details but no ID column found in that list. that's why i am sending the billing address ID for select shipping option this is my code
const newState = await service.selectShippingOption(billing_ID, Shippingoption_ID);
after that i am going to direct payment options my code is
const payment = await service.loadPaymentMethods();
let paymentmethod=payment.data.getPaymentMethods();
in this function i am getting all the payment options details then i go for payment my code is
wait service.initializePayment({ methodId: 'testgateway' });
const payment = {
methodId: 'testgateway',
paymentData: {
ccExpiry: { month: 10, year: 20 },
ccName: 'BigCommerce',
ccNumber: '4111111111111111',
ccType: 'visa',
ccCvv: 123,
},
};
After complete this function this function return a error
Error: "Your order is missing a shipping method. Please return to the
shopping cart and checkout again."

data change doesn't reflect in vue application

In my Vue application I am trying to create a simple table with changeable column sequence. In the data structure I keep all column data with its thead. I use compute to calculate rows from column data using matrix transposion. However any change I do to dynamicTable.columns doesn't reflect in the view.
function transpose(a)
{
return a[0].map(function (_, c) { return a.map(function (r) { return r[c]; }); });
// or in more modern dialect
// return a[0].map((_, c) => a.map(r => r[c]));
}
var tData = {
columns:[
{thead:'isbn',
tdata:[1,2]},
{thead:'name',
tdata:['rose','flower']},
{thead:'price',
tdata:['10','15']},
{thead:'author',
tdata:['john','jane']},
{thead:'page count',
tdata:['396','149']},
{thead:'print date',
tdata:['2001', '1996']}
]
}
var dynamicTable = new Vue({
el: '#dynamicTable',
data: tData,
computed:{
rows: function(){
arr = [];
this.columns.forEach(function(element){
arr.push(element.tdata);
});
return transpose(arr)
}
}
})
For example I want to change the order of isbn column with price,
a=dynamicTable.columns[0]
b=dynamicTable.columns[2]
dynamicTable.columns[0]=b
dynamicTable.columns[1]=a
data changes but changes are not reflected. What is the problem here?
As mentioned in the documentation, this is a JavaScript limitation. Direct changes to an array are not detected by Vue.
One workaround for this, is to use Vue.set(), as instructed in the link.

Dojo gridx: using "onAfterRow" disables "onCellWidgetCreated"?

When creating a gridx, I use the following column definition to insert an Edit button in to the last cell of each row:
var editColumn = { field : 'Edit', name : '', widgetsInCell: true,
onCellWidgetCreated: function(cellWidget, column){
var btn = new Button({
label : "Edit",
onClick : function() {
console.log('Do stuff here');
});
btn.placeAt(cellWidget.domNode);
}
};
columns.push(editColumn);
var grid = new Grid({
cacheClass : Cache,
store : store,
structure : columns,
modules: ["gridx/modules/CellWidget"]
}, 'gridNode');
grid.body.onAfterRow = function(row){
...do stuff on the row here
};
Whne I include the onAfterRow function the row processing happens but the OnCellWidgetCreated does not. Each function seems wo work in absence of the other. Any suggestions on how I can: (1) format the rows according to row data AND (2) insert the button widgets in the last cell of each row?
Ok, solved it. Rather than assign the grid.body.onAfterRow, the way that worked for me was:
aspect.after(grid.body,'onAfterRow',function(row){
key = row.id;
if ('anulada' in row.grid.store.get(key)){
if(row.grid.store.get(key).anulada == true){
row.node().style.color = 'gray';
}
}
},true);
You need to require "dojo/aspect".