How to access custom sublist lines in netsuite?

101 views Asked by At

On sales order record, there is custom sublist "Pick Tasks" which is in the related records sublist.

Pick Tasks sublist is a custom sublist and created using saved search.Now I want to access these sublist lines. I am not able to find internal Id of this custom sublist to getlinecount and access lines from sales order record. Please Help!

I tried to access sublist by using custom sublist id which is in the Customization->Forms->Sublists->list var numLines = objRecord.getLinecount({ sublistId: 'custsublist_22_7621183_625' }); log.debug("numLines",numLines);

1

There are 1 answers

0
Ahmed Khaled On

If you're dealing with a sublist in NetSuite that sources its data from a saved search and you want to access it programmatically, you can take a different approach. Instead of using the standard method like {record}.getLineCount({sublistId}) and looping through the lines, you can load the source saved search using search.load. Next, add a filter to the loaded search with the value of the field you're interested in, which is available in the availableFilters array of the saved search. Finally, execute the search, and the results obtained will correspond to the data in the sublist.

Here's a basic example:

// Load the saved search
let mySavedSearch = search.load({
    id: 'your_saved_search_id'
});

// Add a filter to the saved search based on the field value
mySavedSearch.filters.push(search.createFilter({
    name: 'your_field_id',
    operator: "anyof", // change operator as you want
    values: 'desired_field_value'
}));

// Execute the search
let searchResults = mySavedSearch.run().getRange({
    start: 0,
    end: 1000 // Adjust the range as needed
});

// Process the search results as needed
for (let i = 0; i < searchResults.length; i++) {
    let result = searchResults[i];
    // Do something with each result
}

This approach allows you to retrieve the same data that is displayed in the sublist, providing flexibility in handling and manipulating the results programmatically.