Hope you can assist.
I am trying to add the results of a saved search into a custom column list I created 'on-the-fly' using an user event script. I have historically been successful using SuiteScript 1.0 but now transitioning to 2.0, it does not seem possible.
To demonstrate my code, I first build a UE script, creating a custom column list using the 'serverWidget' module:
if (recordType === 'journalentry') {
log.debug('works')
var objLineSublist = getForm.getSublist({id: 'line'});
// Add several custom fields to the form
var entityField = objLineSublist.addField({
id: 'custpage_entity',
type: serverWidget.FieldType.SELECT,
label: 'Entity'
});
}
My UE script works fine.
I now create a client script; first checking the account type is A/R or A/P, and depending on which of these are selected, the custom list (custpage_entity) will populate with customer or vendor data from a saved search. As this is a client script, I cannot access the properties of the serverWidget module to capture the sublist fields (same way I used it on the UE script). I noticed the "currentRecord.getField" object which I could use instead but sadly did not work. Here is my code:
var customEntity = currentRecord.getField({fieldId: 'custpage_entity'});
log.debug('customEntity', customEntity);
if (getAcctType === 'AcctRec' || getAcctType === 'AcctPay') {
var recordType = '';
if (getAcctType === 'AcctRec')
recordType = 'customer'
else recordType = 'vendor';
log.debug('getAcctType', getAcctType + ' | ' + recordType);
// Insert a blank option.
customEntity.insertSelectOption({ value: 'test', text: 'test' })
//Execute saved search
var getCustomerResults = getEntityListFromSearch(recordType);
getCustomerResults.run().each(function(result){
// .run().each has a limit of 4,000 results
customEntity.insertSelectOption({
value: result.getValue({name: 'internalid'}),
text: result.getValue({name: 'entityid'})
})
return true;
});
}
If you can assist what I am doing wrong, that would be most helpful! I should note: I need this to work on FIELDCHANGE of the 'account' column field in the client script.
You need to insert your options in the dropdown from the server side (UE script) or in a pageInit event in the client script (but this would only work without your fieldChange)
I would suggest to create two different dropdowns in the UE script and insert the options one for vendors and one for customers and add a CSS class to hide them. In the fieldChange event display the correct dropdown based on the user selection using CSS.