Hi All, I am creating a Transfer Order using Afte...
# suitescript
d
Hi All, I am creating a Transfer Order using AfterSubmit(Applied to Sales Order), while creating transfer order I am setting the transfer order Order # dynamically ( Last Processed Transfer Order# increment by 1). I can see few Transfer Order# are blank and few have the same Order#. AfterSubmit(SO) gets triggered by RestLet and web services as well. How to solve this Order# issue?
b
are the duplicates created at the same time?
d
Different time
b
its unlikely to be a concurrency issue then
what does the order # logic look like
d
function lastProcessedSTO() { var stoNo; try { //customsearch1767 var transferorderSearchObj = search.create({ type: "transferorder", filters: [ ["type", "anyof", "TrnfrOrd"], "AND", ["numbertext", "startswith", "STO"] ], columns: [ search.createColumn({ name: "tranid", summary: "MAX" }) ] }); var searchResultCount = transferorderSearchObj.runPaged().count; log.debug("transferorderSearchObj result count", searchResultCount); transferorderSearchObj.run().each(function(result) { stoNo = result.getValue({ name: "tranid", summary: "MAX" }); }); return stoNo; } catch (error) { log.error('lastProcessedSTO Error', (error.message && error.name) ? error.name + ': ' + error.message + ': ' + error.stack : error.toString()); } }
var stoNo = lastProcessedSTO(); log.debug("lastProcessedSTO", "stoNo ==> " + stoNo);
b
you probably need to do something better than max of tranid
tranid is a string
d
i will get stoNo as "STO134-1"
if (stoNo != 0) { stoNo = stoNo.split("-")[0].match(/\d/g).join(""); } log.debug("lastProcessedSTO digit", "stoNodigit ==> " + stoNo); stoNo = parseInt(stoNo);
stoNo += 1;
This how finally i am getting it incremented finally
b
search.createColumn({ name: "tranid", summary: "MAX" });
that wont get you the largest tran id
primarily because tranid is not a number
d
oh okay
var transferorderSearchObj = search.create({ type: "transferorder", filters: [ ["type", "anyof", "TrnfrOrd"], "AND", ["numbertext", "startswith", "STO"], "AND", ["mainline", "is", "T"] ], columns: [ /* search.createColumn({ name: "tranid", summary: "MAX" }) */ search.createColumn({ name: "tranid" }), search.createColumn({ name: "internalid", sort: search.Sort.DESC }) ] }); var searchResult = transferorderSearchObj.run().getRange({ start: 0, end: 5 }); if (searchResult.length > 0) { stoNo = searchResult[0].getValue('tranid'); }
is this fine
?