Reputation: 35
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
Upvotes: 0
Views: 3820
Reputation: 7343
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))))
}
}
Upvotes: 1
Reputation: 15367
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.
Upvotes: 0