Does anyone know if there is a way to add a multi-select drop down filter in a suitelet that is displaying a sublist from an already existing saved search. One of the columns is "customer" and I would like to add a drop-down that filters by the customers on the sublist. I already have the code setup, I was just wondering if this could be done. Thanks
Asked
Active
Viewed 3,336 times
0
-
what record type is your saved search on ? you mean to say you are displaying search results as sublist and you want to filter the search results based on selected customers from drop down? – prasun Nov 17 '15 at 15:28
-
The saved search is of transaction type. One of the columns is "customer", that is pulling names from the forms I am searching for. I am able to display the saved search in a subtab of a suitelet I created. I would just like to add a multi-option select filter on the top that filters by "customer". (basically exactly what you said). I know I have to invoke addselectoption(), I'm just having a tough time implementing it as it keeps returning back null data from the sublist. – L.B. Nov 17 '15 at 16:33
-
can you add your code snippet on what you are trying? – prasun Nov 17 '15 at 16:40
-
I replied to bk witha link to my suitelet code. From that sublist I created there, I am simply trying to add a select filter that people can further sort the sublist by. This select filter is to be populated with values from a column in that sublist, in this case it just happens to be "customer names". – L.B. Nov 17 '15 at 16:56
-
You mean you want to re-run the search and display selected customers' transactions only? – prasun Nov 17 '15 at 17:00
-
Hm now that you mention it, that seems to be the only route. I was kind of hoping the drop down filter would just hide the results that aren't selected , but I don't think there is a way for that . – L.B. Nov 17 '15 at 17:13
-
you need to resend the ajax, it would be more of server side reload than client side filtering. To filter on client side you would need to use your own HTML/CSS/JS than nlobjform to avoid DOM dependency with NS – prasun Nov 17 '15 at 17:25
-
Thank you for all your help prasun, I will try that – L.B. Nov 17 '15 at 18:43
2 Answers
1
You can use your suitelet as
if (request.getMethod() == 'GET'){
var field = form.addField('custpage_customers', 'multiselect', 'Customers');
var addedCustomers = [], selectedCustomers;
var searchResults= nlapiSearchRecord('transaction','customsearchID');;
//add customers options
searchResults.forEach(function(res){
if(addedCustomers.indexOf(res.getValue('customer')) !== -1) return;
field.addSelectOption(res.getValue('customer'), res.getText('customer'))
});
//filter sublists
//add customer options
if(request.getParameter('customerids')){
addedCustomers = JSON.parse(request.getParameter('customerids'));
searchResults = searchResults.filter(function(res){
return addedCustomers.indexOf(res.getValue(customer)) !==-1)
});
//if above search result reduces your search results you may just want to re-run search as below than filtering it
//searchResults = nlapiSearchRecord('transaction','customsearchID',['customer', 'anyof', JSON.parse(request.getParameter('customerids'))]);
}
//add sublist code goes here
//set a client script
form.setScript(MY_GLOBAL_CLIENT_SCRIPT)
// set response
}
Then write a global client script which would fire on field change
function FieldChanged(type, name)
{
// Prompt for additional information, based on values already selected.
if ((name == YOUR_MULTISELECT_FIELD_ID))
{
//send AJAX with additional argument
nlapiRequestURL(SUITELET_URL + "&customerids=" +encodeURIComponent(JSON.stringify(nlapiGetFieldValue(YOUR_MULTISELECT_FIELD_ID))))
}
}

prasun
- 7,073
- 9
- 41
- 59
-
-
This should work except that it progressively reduces your customer filter to the customers in the last query. You'd be better off always running the full query and then filtering by the selected customer ids. e.g. just get searchResults with no extra filter and fill in the drop-down. Use the third arg of addSelectOption to select the chosen customers then `searchResults = searchResults.filter...)` and then fill the sublist. – bknights Nov 17 '15 at 20:41
0
I generally just go with native elements for things like this and manage them the way you would manage any client side interaction. I generally add a field of type inlinehtml in my suitelet code and then populate the select list with client (field changed and post sourcing) events and AJAX calls.

bknights
- 14,408
- 2
- 18
- 31
-
Thank you for the response bk. I don't know if I am understanding you correctly, but that would kind of defeat the purpose of having the filter on the page if I have it in post sourcing. I appreciate all your help on http://stackoverflow.com/questions/33742377/netsuite-saved-search-to-suitelet-sublist. I am basically trying to add an available multi-select filter to that suitelet that is just populating the "customer names" so people can sort the sublist by it. – L.B. Nov 17 '15 at 16:52
-
Different events then but same answer. In short I don't know of any Netsuite API for adding a filter section to a sublist but you can easily add your own drop-down and then sort or re-filter your results based on the selection. I believe you can indicate the drop -down is associate with the sublist by putting them into their own field group but this will not look like an integrated filter. – bknights Nov 17 '15 at 17:11
-