Scenario:
We would like to update the memo text of the amortization entries in a journal with the memo text from the associated bill. It is possible that multiple Amortization schedules or Bills are associated with the Journal Entry.
Below is the code and it is divided into 6 parts. In part 6 we want to look for the line in the vendor bill where amortizationsched is same as the sublistFieldValue. However, on doing this step we are getting -1, but there is a record with that amortizationsched. We have checked if the bill is getting loaded properly and the internalId is correct.
Any help will be great.
//1. Load the Journal Entry.
var rec = record.load({
type: record.Type.JOURNAL_ENTRY,
id: id,
isDynamic: false
});
// Count the number of lines on the Items sublist
var itemCount = rec.getLineCount({"sublistId": "line"});
for(var i=0; i < itemCount; i++) {
// 2. Get the Amortization Schedule
var sublistFieldValue = rec.getSublistValue({
sublistId: 'line',
fieldId: 'schedulenum',
line: i
});
//3. Load the Amortization Schedule
var rec1 = record.load({
type: record.Type.AMORTIZATION_SCHEDULE,
id: sublistFieldValue,
isDynamic: false
});
//4. Get the Related Bill Record
var bill1 = rec1.getValue({
fieldId: 'sourcetran'
});
//5. Load the Bill Record
var rec2 = record.load({
type: record.Type.VENDOR_BILL,
id: bill1,
isDynamic: false
});
//6. Get the expense line, by looking for internalId of the amortization schedule
var lineNumber = rec2.findSublistLineWithValue({
sublistId: 'expense',
fieldId: 'amortizationsched',
value: sublistFieldValue
});
}