RE: How to create a filtered drop down list in form field in suitelet

I have added a form select field and added it’s source as customer. Now I want the customers to be filtered by subsidiary. For this I have create a search and added results to the field using addSelectOptions() but I need it to show up as a standard field where we can search by typing keywords. May I know is this possible?

Shivani Rookie Asked on November 5, 2019 in SuiteScript.

@leacc

Hi

It is not not working for me. I tried the same way

Below is my client script

/**
* @NApiVersion 2.0
* @NScriptType ClientScript
* @NModuleScope Public
*/

define([‘N/search’, ‘N/currentRecord’], function(search,currentRecord) {
var record = currentRecord.get();

function fieldChanged(context) {
if(context.fieldId == ‘custpage_customers’) {
/* var location = record.getValue(‘custpage_customers’);

if(location == ”) return;*/

// var vendorSearch = search.create({
// type: ‘vendor’,
// filters: [[‘custpage_customers’,’is’,location]],
// columns: [‘entityid’]
// });

// var vendorSearchResults = vendorSearch.run().getRange({ start: 0, end: 1000 });
var filters = [
search.createFilter({
name: ‘subsidiary’,
join: ‘msesubsidiary’,
operator: search.Operator.ANYOF,
values: subsidiary
})
];
var paymentSearch = search.create({
‘type’:’customer’,
‘filters’:filters,
‘columns’:[‘entityid’]
});
var componentsSearch = ”;
var counter = 0;
var vendfield = record.getField(‘custpage_customers’);
vendfield.removeSelectOption({value : null});
for(var i=0; componentsSearch.length >= 1000 || i == 0; i++){
componentsSearch = paymentSearch.run().getRange({
start: counter,
end: counter + 1000
});
if( componentsSearch.length > 0 ){
for(var j=0; j<componentsSearch.length; j++){
/*var id=componentsSearch[j].getValue({name :’internalid’});
var entityName=componentsSearch[j].getValue({name :’entityid’});*/
//log.debug(“paymentSearch result count”,componentsSearch[j].getValue({name :’entityid’}));
/*customerField1.addSelectOption({value : id, text : entityName});*/
vendfield.insertSelectOption({
value : componentsSearch[i].id,
text : componentsSearch[i].getValue(‘entityid’)
});
}
}
counter += componentsSearch.length;
}

}
}

return { fieldChanged : fieldChanged };

});

6 days ago.

Where’s the line where you’re getting the value of ‘subsidiary’? I would suggest troubleshooting the search first if it’s returning a result. Also, ensure that you’re referencing the correct Client Script.

6 days ago.
Add Comment
1 Answers

Just published an article that may answer your question. The sample context is different but the syntax should be similar. Hope this helps!

Beginner Answered 6 days ago.
Add Comment

Your Answer

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