This function can be used to find the tax rate of a given tax code. Saved search is used for this purpose
function searchTaxRate(line_tax) {
try {
if (line_tax) {
var salestaxitemSearchObj = search.create({
type: "salestaxitem",
filters: [
["internalidnumber", "equalto", line_tax]
],
columns: [
search.createColumn({
name: "name",
sort: search.Sort.ASC,
label: "Name"
}),
search.createColumn({
name: "rate",
label: "Rate" })
]
});
var searchResult = salestaxitemSearchObj.run().getRange({
start: 0,
end: 1
});
var tax_rate
for (var j = 0; j < searchResult.length; j++)
{
tax_rate = searchResult[j].getValue({
name: "rate",
});
log.debug('tax_rate', tax_rate)
}
return tax_rate;
} else {
return false;
}
} catch (e) {
log.debug('e', e)
}
}