Enable Line Item Shipping (ismultishipto) moves shipping information from the form header to the line level. So when manually rendering a pick ticket with the N/render
module, you must pull data from a line item to populate the shipaddress
and shipmethod
fields.
Also, if shipping from multiple locations, you must filter out line items that don’t match the desired location.
// this is the record we'll feed to the rendering library
// please note we NEVER save this record, we just feed it
// to the renderer in it's modified forms
const rec = record.load({
id: id,
type: 'salesorder'
});
// placeholder for the address
let address = '';
// shipmethod is passed to the template by number
let shipmethod = 0;
// iterate the lines and remove ones that aren't for location = 1
const lc = rec.getLineCount({ sublistId: 'item' });
for (let i = 0; i < lc; i++) {
const itemLocation = rec.getSublistValue({
sublistId: 'item',
line: i,
fieldId: 'location'
});
// not location 1, so toss it out
if (itemLocation !== '1') {
rec.removeLine({
sublistId: 'item',
line: i
});
}
// if the item location matches, we get the address string
if (itemLocation === '1') {
shipmethod = parseInt(rec.getSublistValue({
sublistId: 'item',
line: i,
fieldId: 'shipmethod'
}).toString() || '0');
address = rec.getSublistValue({
sublistId: 'item',
line: i,
fieldId: 'shippingaddress_text'
});
}
}
// use the address string in the 'shipaddress' field
rec.setValue({ fieldId: 'shipaddress', value: address });
rec.setValue({ fieldId: 'shipmethod', value: shipmethod });
var renderer = render.create();
// tell the renderer to use the modified record as it's datasource
// remember that we don't need to save it for it to work
renderer.addRecord({
templateName: 'record',
record: rec
});
// set the templace internalid of the Advanced PDF/HTML Template in the NS acct
renderer.setTemplateById({ id: 99 });
// renderAdPdf returns a File type
const pdfFile = renderer.renderAsPdf();