Hi all - does anyone know what the fundamental dif...
# suitescript
y
Hi all - does anyone know what the fundamental differences are between "context.newRecord" vs loading that record via record.load(...)? E.g. say you have a customer refund, if I try to get the "deposit" sublist off of this method, then it works:
var numLines = context.newRecord.getLineCount({
sublistId: 'deposit'
});
Outcome: numLines displays 1 However if I try it off of the loaded record, it doesn't work:
var customerRefund = record.load({
type: record.Type.CUSTOMER_REFUND,
id: context.newRecord.id
});
var numLines = customerRefund.getLineCount({
sublistId: 'deposit'
});
Outcome: numLines displays -1 Furthermore, the following returns a (correctly applied) count of deposit applications, however in the UI, clicking on the link takes you to the customer deposit, NOT the deposit application:
var numLines = customerRefund.getLineCount({
sublistId: 'apply'
});
Just trying to see if anyone can explain why one might work over the other, and maybe if there is a good way to frame decisions around when to use each different option?
b
the newRecord reflects the record as submitted, the most obvious effect is that it usually has new data on it somewhere
the loaded record reflects the record in the database, and for your case, is equivalent to editing the record
some records like customer refunds have different data on them depending on if its create, edit, or view
you dont usually have much choice in the matter, most of the time you use the newRecord in user event scripts, it has the most up to date data
sometimes you want old data, in which case you use the oldRecord
occasionally you want data that is generated after the record is created, like tranid, which means you use a search or query to get the tranid
you can also load the record aftersubmit to get the tranid, but that tends to be less efficient in terms of performance
y
Ah thank you! This is some really good insight - it's just so strange to me that records will have differing data depending on whether you're performing a view / create / edit, and something I will have to get used to understanding a bit better. To me I would've thought that the data in the DB is the true data, and the UI just works to change the view for you, but seems like in some cases you do actually get different information through
b
you can see the difference in the ui, take a look at the sublists you have available in create vs edit
y
Thank you - I'll definitely give that a go and see :)