NetSuite’s Suitelets offer a powerful way to create custom pages, forms, and interfaces. One of the common tasks when working with Suitelets is to dynamically update a sublist based on user interaction or other factors. This can be accomplished by using a combination of SuiteScript 2.0 Suitelet and Client Script.
Here’s a step-by-step guide on how to update a sublist dynamically in a Suitelet page using a Client Script:
1. Create the Suitelet
First, you’ll create a Suitelet that will render the form with a sublist. The sublist will be populated with data when the form is loaded.
In this Suitelet, a form with a select field (custpage_item) and a sublist (custpage_sublist) is created. The sublist will be dynamically populated based on the item selected in the custpage_item field.
2. Include the File Id of the client script from the NetSuite>FileCabinet.
your_form_variable.clientScriptFileId = (internal_Id_from_Netsuite);
3. Create the Client Script
Next, create the Client Script that will handle the dynamic updating of the sublist when the item is selected.
function pageInit(scriptContext) {
window.onbeforeunload = null;
}
function fieldChanged(scriptContext) {
let filter = scriptContext.fieldId;
let rec = scriptContext.currentRecord;
let x = rec.getValue({fieldId: ‘id of the field in suitelet’}) || ”;
if(scriptContext.fieldId === ”id of the field in suitelet”){
document.location = url.resolveScript({
deploymentId: ‘Scriptdeploymentid’,
scriptId: ‘Scriptid’,
params: {
new_variable: value|| ”, // passing the new value
}
})
}
}
4. In the Suitelet Script, store this new values to a variable using scriptContext.request.parameters.new_variable || ”;
5. Apply the variable value into the Search filter and the filter will work dynamically.