darrenhillconsulting
10/29/2024, 2:09 AMCeligo AI
10/29/2024, 2:10 AMAI generated answer (using internal Slack threads):In SuiteScript 2.1, you can loop through all the rows in a sublist using the
pageInit
event of a client script. The pageInit
event is triggered when the page is initialized, which is after all records and sublists are loaded.
Here is a sample code snippet that demonstrates how to do this:
javascript
/**
* @NApiVersion 2.1
* @NScriptType ClientScript
*/
define(['N/currentRecord'], function(currentRecord) {
function pageInit(scriptContext) {
var record = scriptContext.currentRecord;
var sublistId = 'your_sublist_id'; // replace with your sublist id
var lineCount = record.getLineCount({sublistId: sublistId});
for (var i = 0; i < lineCount; i++) {
var value = record.getSublistValue({
sublistId: sublistId,
fieldId: 'your_field_id', // replace with your field id
line: i
});
console.log('Line ' + i + ' Value: ' + value);
}
}
return {
pageInit: pageInit
};
});
In this script, pageInit
function is defined which is triggered when the page is loaded. Inside this function, we get the current record and the line count of the sublist. Then we loop through each line in the sublist and get the value of a field.
Please replace 'your_sublist_id'
and 'your_field_id'
with your actual sublist id and field id.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
10/29/2024, 2:10 AMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840385497
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838067114
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836326897
Celigo AI
10/29/2024, 2:10 AM