darrenhillconsulting
10/20/2024, 9:32 PMCeligo AI
10/20/2024, 9:32 PMAI generated answer (using internal Slack threads):To read the values of a sublist's columns in the POST of a Suitelet using SuiteScript 2.1, you can use the
request
object's getSublistValue
method. This method allows you to retrieve the value of a sublist field on a specific line.
Here is a sample code snippet:
javascript
/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define(['N/ui/serverWidget', 'N/redirect'], function(ui, redirect) {
function onRequest(context) {
if (context.request.method === 'GET') {
var form = ui.createForm({title: 'My Form'});
// Add your sublist and fields here
// ...
context.response.writePage(form);
} else {
var sublistId = 'yourSublistId'; // replace with your sublist id
var fieldId = 'yourFieldId'; // replace with your field id
var lineCount = context.request.getLineCount({sublistId: sublistId});
for (var i = 0; i < lineCount; i++) {
var fieldValue = context.request.getSublistValue({
sublistId: sublistId,
fieldId: fieldId,
line: i
});
log.debug('Field Value', fieldValue);
}
// Redirect or do something with the values here
// ...
}
}
return {
onRequest: onRequest
};
});
In this script, we first check if the request method is 'GET'. If it is, we create the form and write it to the response. If the request method is 'POST', we get the line count of the sublist using context.request.getLineCount
, then loop through each line of the sublist and get the value of the field using context.request.getSublistValue
.
Please replace 'yourSublistId'
and 'yourFieldId'
with your actual sublist and field IDs.
******
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/20/2024, 9:32 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847790897
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.846324325
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.844432831
Celigo AI
10/20/2024, 9:32 PM