Hi, I am having some problems getting field select...
# suitescript
d
Hi, I am having some problems getting field select options on a client script. On the fieldChanged event I am setting the value of another field. This field filters select options for another field. When I try to get the select options it works the first time, but every other time it just returns the same value as the first run? Any help appreciated
function fieldChanged(context) {
    
var record = context.currentRecord;
    
switch(context.fieldId){
        
case 'custpage_project':
            
var sublistLine = record.getCurrentSublistIndex({
                
sublistId: 'timeitem'
            
});
            
var value = record.getCurrentSublistValue({
                
sublistId: 'timeitem',
                
fieldId: 'custpage_project'
            
});
            
record.setCurrentSublistValue({
                
sublistId: 'timeitem',
                
fieldId: 'customer',
                
value: value,
                
ignoreFieldChange: true
            
});
            
var standardTask = record.getSublistField({
                
fieldId: 'casetaskevent',
                
sublistId: 'timeitem',
                
line: sublistLine
            
});
            
var standardTaskOptions = standardTask.getSelectOptions();
            
console.log('Standard Task Options: ' + JSON.stringify(standardTaskOptions));
            
var standardTaskOptions = null;
            
break;
    
}
}
t
You should wait for the sourcing to happen.
d
I was thinking it might be something along those lines but I don't think it would work the first time if that was the case? I might be wrong though
b
SetCurrentSublistValue is asynchronous, which might be the strangeness of the first run
t
@battk Can postsourcing event be the solution of this ?
d
Just tested and got the same results
b
as in did you stop using ignoreFieldChange and move the standardTaskOptions into a postSourcing entry point
or did you simply move everything into postSourcing
d
I moved standardTaskOptions into postSourcing
I'm going to try and do things differently and avoid getting the select options. Thanks for your help