RE: Accessing items from a custom suitelet list?
I have a Suitelet that loads a saved search and outputs the results into a custom list. Is there a simple way to access the list from a client script? I mean I could probably get the list items by directly accessing the DOM but I suppose there is an easier way that I am missing.
For example if I have a Suitelet with a custom list and button. When I click on the button a function on the client script is called that outputs the list items to the console.
Thanks for any help.
You can attach a client script to a suitelet and also add buttons which link to the client script for functionality.
form.addButton({ id: 'buttonid', label: 'Button Name', functionName: 'functionName' }); form.clientScriptModulePath = './myscript.js';
Then in your Client Script you would create a function ‘functionName’, include it in the return statement and then you can use this function to get values from your sublist.
Sorry, maybe I wasn’t clear enough. I already have a button setup and am able to call a function from a client script. What I’m looking for is what to put inside the function that allows me to access the list.
Thanks for your help though.
As mentioned by @dbarnett, use N/currentRecord
var listRecord = currentRecord.get(); var listLineCount = listRecord.getLineCount({ sublistId: "your_sublist_id_here" }); for (var i = 0; i < listLineCount; i++) { var listValue = listRecord.getSublistValue({ sublistId: "your_sublist_id_here", fieldId: "your_field_id_here", line: i }); console.log(listValue); }
Thanks
Can i have the code please. Since this is similar to my requirement.