Hi Guys, I'm getting similar error. ```{"message":...
# suitescript
m
Hi Guys, I'm getting similar error.
Copy code
{
  "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": {}
}
@battk any idea why i'm getting this error
b
not really
cant really give you anything beyond the error message without the code
m
When I'm calling the save search it returned the correct result in purchaseOrder UE before Load whenever I am trying to access record like
lineItem.line
rhinoexception occrs
b
not enough code
your stack trace says the problem begins on line 74
i dont know which line is 74
m
Copy code
function 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
                            }
                        }
                    }
b
i dont think you understand how to read stack traces if you think what you shared is helping
m
b
if you want help, you need to start sharing the line that caused the error
your error is a fairly common error that occurs when you try treating something as an object when it is actually undefined
m
purchaseOrderLines = 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 checked
b
i dont really see that anywhere in your code
but if that line was causing the error, then purchaseOrderLines[0] is undefined
and your code is equivalent to
Copy code
(undefined).line
m
What you are saying is right, but @ShawnTalbert says it is Netsuite bug it will be resolved in SS 2.1
I know this is irritating you but this is exactly happen, very strange, here I'm login together
b
your reliance of logs is hurting you here
log.debug does not actually log the object in the details
s
The issue we discovered in NFT is unrelated and long since resolved by NS. Note that
TypeError
is a generic error - there are many ways to arrive at a
TypeError
in JS.
it actually looks like you're trying to use an NFT-like syntax without using NFT 🙂 In other words,
purchaseOrderLines[0]
is of type
SearchResult
- it is NOT an object you can interrogate just by looking at the JSON stringify() output.
So there will be no
line
field on
purchaseOrderLines[0]
because I don't think a
SearchResult
has a
line
property?
With NFT you would have that line field accessible and all that code you pasted would be roughly:
Copy code
const 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

})
m
Do i need to add module because Transaction, Seq, LazySearch are undefined
s
those are types from NFT...
if you want to stick with your original verbose code. you'll need to use
getValue()
- see the NS documentation for
SearchResult
on how to retrieves values from your search .
m
got it @stalbert, is there a way to update view page lineitem fields I want to update lineitem fields
on view page