I'm working on a set of SuiteScripts that are intended to synchronize a pair of custom fields between two different record types. I have most of the logic complete, but I've been stuck at a brick wall for almost two days.
Specifically, I'm trying to access the Related Records on an Opportunity (from the beforeLoad() entry point of a User Event on the Opportunity), which I understand is just a Transaction. The Related Records I'm trying to reach are Cases. Of course, in my testing, I have an Opportunity which was created from a Case, and I can see the Case in the Related Records sublist on the Opportunity (and vice versa).
However, I cannot figure out how to access the Case that created the Opportunity. The closest I got was determining that there's a cases sublist, however, that list is empty. Here's a simplified example of what I tried (in a User Event on the Opportunity):
const beforeLoad = ( context ) => {
const opportunity = context.newRecord;
const lineCount = opportunity.getLineCount({ sublistId: 'cases' });
}
In the example above, the lineCount variable is 0, but I expect it to be 1 since the Opportunity does have a related Case. After some reading, I also tried accessing the links sublist, but .getLineCount() returns -1.
I also dumped .getSublists() so I could see all possible sublists for an Opportunity, but nothing other than the two I tried seemed relevant.
I know that Transaction Lines have a createdFrom field, so I thought maybe the main line of the Opportunity might have that field set to the internal ID of the related Case — nope (in fact, the createdFrom on all Transaction Lines on the Opportunity are null).
Also, I know that Transactions (and Transaction Lines) have Previous Links and Next Links, but I understand that those point only to other Transactions (and a Case is not a Transaction).
I have tried several other chunks of SuiteScript, and even tried to draft a SuiteQL query, to try to figure out how to get the Case related to an Opportunity, but nothing I tried has worked.
I used the Records Catalog to browse the tables and fields to see if I could find a JOIN or a map table between Cases and Transactions, but to no avail. I even used an ODBC connection to manually browse all 3,344 tables to see if I could recognize a map table and found nothing.
So… how the heck can I see Related Records from a User Event script for a Transaction? The NetSuite UI can do it, why can't I?