Been pulling my hair out for hours with this. If ...
# suitescript
d
Been pulling my hair out for hours with this. If one of you NetSuite gurus were able to help I would be very grateful. I'm using the NetSuite timesheet form. In the User Event script I generate a custom select field in the sublist. I want to set the value of another sublist field when the custom field changes. My code works when entering new time entries but when I try to edit time entries I run into some problems. There are two seperate issues depending on the value I enter for the ignoreFieldChange property, only need to figure out one of them. 1st problem - When the ignoreFieldProperty is set to true the code seems to work. I select the custom field and it changes the value of the other field, but when I save the timesheet it reverts itself back to what it was before. 2nd problem - When the ignoreFieldProperty = false, I select the custom field and it sets the value of the other field but it throws up an error on the page and stops executing the code. This only happens the first time I edit/select the custom field value, if I select another value after then it works as it should. Here is my fieldChanged function and the error message that pops up for the 2nd issue.
Copy code
function fieldChanged(context) {
    var record = context.currentRecord;
    
    if(context.fieldId == 'custom_field'){
        var value = record.getCurrentSublistValue({
            sublistId: 'timeitem',
            fieldId: 'custom_field'
        });

        var line = record.getCurrentSublistIndex({sublistId: 'timeitem'});

        record.selectLine({
            sublistId: 'timeitem',
            line: line
        });

        record.setCurrentSublistValue({
            sublistId: 'timeitem',
            fieldId: 'casetaskevent',
            value: value,
            ignoreFieldChange: true
        });

        record.commitLine({sublistId: 'timeitem'});
    }
}
b
Dont try to change the line, and preferably dont try to commit the line
s
I might try this
This code is unchecked so its just an idea
var targetfld = 'custom_field';
var targetlist = 'timeitem';
function fieldChanged(context) {
if(context.fieldId == targetfld && context.sublistId == targetlist)
 
var record = context.currentRecord;
    
var val = record.getCurrentSublistValue({
            
sublistId: targetlist,
             
fieldId: targetfld});
objRecord.setCurrentSublistValue({
 
sublistId: targetlist, targetfld: 'casetaskevent', value: val, ignoreFieldChange: true
 
});
    
}
}