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.

Rookie Asked on September 17, 2019 in SuiteScript.
Add Comment
2 Answer(s)
Best answer

use currentRecord.get() in your client script to get the current “Record” of your Suitelet form. From there you should be able to reference the N/currentRecord section in the HelpCenter and use all the operations you are familiar with to get sublist data etc.

Beginner Answered on September 17, 2019.

Thanks for your help this worked.

on September 18, 2019.
Add Comment

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.

Rookie Answered on September 17, 2019.

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.

on September 17, 2019.

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);
}
on September 17, 2019.

Thanks

on September 18, 2019.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.