Hi There
I have a suitelet displaying a saved search (example with fictitious data from a demo account)
I want the client script to return which rows/lines are checked so I can get the corresponding values from them. In this case, if the checkbox is ticked, I want the internal Id from the row's data
This is my script at the moment which is returning the line count though not the sublist field values
Where am I going wrong?
The log debug for "error" is returning
"CurrentRecord.getSublist: Missing a required argument: sublistId (Line: undefined)"
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(["N/currentRecord", "N/url", "N/log"], function (
currentRecord,
url,
log
) {
function pageInit(context) {}
function submitSelectedLines() {
try {
var currentPage = currentRecord.get();
var sublistId = "custpage_sublist"; // Replace with your sublist ID
// Get the selected lines from the sublist
var selectedLines2 = [];
var lineCount = currentPage.getLineCount({
sublistId: sublistId,
});
alert("total line count" + lineCount);
for (var i = 0; i < lineCount; i++) {
var isSelected = currentPage
.getSublist({ id: sublistId })
.getField({ id: "custpage_select" });
alert("isSelected: " + isSelected);
if (isSelected) {
var internalId = currentPage.getSublistValue({
sublistId: sublistId,
fieldId: "custpage_internalid",
line: i,
});
selectedLines2.push(internalId);
alert("Selected lines: " + JSON.stringify(selectedLines2));
}
}
} catch (e) {
var errorMessage = e.message + " (Line: " + e.lineNumber + ")";
log.error({
title: "Error",
details: errorMessage,
});
}
// Generate Suitelet URL with selected lines as parameters
var suiteletURL = url.resolveScript({
scriptId: "customscript_sales_order_invoice",
deploymentId: "customdeploy_sales_order_invoice",
returnExternalUrl: false,
params: {
selectedLines: JSON.stringify(selectedLines2),
},
});
suiteletURL += "&selectedLines=" + JSON.stringify(selectedLines2);
// Open the map/reduce script in a new window
window.open(suiteletURL, "_blank");
}
return {
pageInit: pageInit,
submitSelectedLines: submitSelectedLines,
};
});