MUHAMMAD MUBUSHER ASLAM
06/18/2021, 2:48 PM{
"message": "Cannot read property \"line\" from undefined",
"fileName": "/SuiteScripts/Octavius App/purchaseOrderUE.js",
"lineNumber": 74,
"name": "TypeError",
"stack": "\tat /SuiteScripts/Octavius App/purchaseOrderUE.js:74 (beforeLoad)\n\tat INVOCATION_WRAPPER$sys:26\n\tat INVOCATION_WRAPPER$sys:17\n\tat INVOCATION_WRAPPER$sys:34\n\tat INVOCATION_WRAPPER$sys:1\n",
"rhinoException": {}
}
MUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:20 PMbattk
06/18/2021, 3:23 PMbattk
06/18/2021, 3:24 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:34 PMlineItem.line
rhinoexception occrsbattk
06/18/2021, 3:38 PMbattk
06/18/2021, 3:38 PMbattk
06/18/2021, 3:38 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:43 PMfunction beforeLoad(context) {
try {
if ((runtime.executionContext == runtime.ContextType.USER_INTERFACE) &&
(context.type == context.UserEventType.VIEW)) {
var REC = context.newRecord;
var srchPurchaseOrderLines = search.create({
type: "purchaseorder",
filters:
[
["type", "anyof", "PurchOrd"],
"AND",
["mainline", "is", "F"],
"AND",
["taxline", "is", "F"],
"AND",
["cogs", "is", "F"],
"AND",
["internalid", "anyof", REC.id]
],
columns:
[
search.createColumn({ name: "account" }),
search.createColumn({ name: "line" }),
search.createColumn({ name: "quantitybilled" }),
search.createColumn({ name: "quantityshiprecv" })
]
});
var lines = [];
var results = srchPurchaseOrderLines.run();
const purchaseOrderLines = results.getRange(0, 1000);
var bill = 0;
var receive = 0;
var unbill = 0;
var notreceive = 0;
var REC_LINES = REC.getLineCount({ sublistId: 'expense' });
for (var i = 0; i < REC_LINES; i++) {
var lineNo = REC.getSublistText({ sublistId: 'expense', fieldId: 'line', line: i });
for (var increment = 0; increment < purchaseOrderLines.length; increment++) {
const poline = purchaseOrderLines[increment];
log.debug({
title: 'Line Number: ' + increment,
details: JSON.stringify(poline)
});
if (lineNo == poline['values']['line']) {
if (purchaseOrderLines[increment]['values']['quantitybilled']) {
bill = bill + amount;
//REC.setSublistValue({ sublistId: 'expense', fieldId: 'custcol_billed', value:true, line: i });
} else {
unbill = unbill + amount;
}
if (purchaseOrderLines[increment]['values']['quantityshiprecv']) {
receive = receive + amount
//REC.setSublistValue({ sublistId: 'expense', fieldId: 'custcol_received', value:true, line: i });
} else {
notreceive = notreceive + amount
}
}
}
battk
06/18/2021, 3:45 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:47 PMbattk
06/18/2021, 3:48 PMbattk
06/18/2021, 3:49 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:50 PMpurchaseOrderLines = results.getRange(0, 1000);
this is search result
and when i'm trying to access field of single record it throws error
purchaseOrderLines[0].line
search result has array of record i checkedbattk
06/18/2021, 3:51 PMbattk
06/18/2021, 3:52 PMbattk
06/18/2021, 3:52 PM(undefined).line
MUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:54 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 3:56 PMbattk
06/18/2021, 3:57 PMbattk
06/18/2021, 3:58 PMstalbert
06/18/2021, 4:14 PMTypeError
is a generic error - there are many ways to arrive at a TypeError
in JS.stalbert
06/18/2021, 4:18 PMpurchaseOrderLines[0]
is of type SearchResult
- it is NOT an object you can interrogate just by looking at the JSON stringify() output.stalbert
06/18/2021, 4:18 PMline
field on purchaseOrderLines[0]
because I don't think a SearchResult
has a line
property?stalbert
06/18/2021, 4:32 PMconst REC = new Transaction(context.newRecord)
Seq(LazySearch.from(yourdefinedsearchobject)).map(nsSearchResults2Obj()).forEach( poLine=> {
// your logic with each line and the REC
// e.g.
const found = _.find(REC.expense, expenseLine => expenseLine.line == poLine.line)
found.billingblahlbah = poLine.something
})
MUHAMMAD MUBUSHER ASLAM
06/18/2021, 5:35 PMstalbert
06/18/2021, 5:39 PMstalbert
06/18/2021, 5:40 PMgetValue()
- see the NS documentation for SearchResult
on how to retrieves values from your search .MUHAMMAD MUBUSHER ASLAM
06/18/2021, 5:50 PMMUHAMMAD MUBUSHER ASLAM
06/18/2021, 5:50 PM