Hello, On a time entry, I am trying to populate t...
# suitescript
d
Hello, On a time entry, I am trying to populate the service item with the value of the billing class. The service item and billing class is a 1 to 1 relationship. Also the service item field is mandatory. I cannot get passed the mandatory field. Does anyone have any suggestions?
Copy code
function beforeSubmit(scriptContext) {
    if (scriptContext.type !== scriptContext.UserEventType.CREATE &&
        scriptContext.type !== scriptContext.UserEventType.EDIT) {
        return;
    }
    var timeEntry = scriptContext.newRecord;
    var employee = timeEntry.getValue({ fieldId: 'employee'});
    if (!employee) {return}

    var employeeName = record.load({ type: record.Type.EMPLOYEE, id: employee });
    var billingClass = employeeName.getValue({ fieldId: 'billingclass'});

    timeEntry.setValue({ fieldId: 'item', value: billingClass });
}
b
are you saying that service items and billing classes have the same name
or that service items and billing classes have the same internal id number
d
yes they both have the same name
as in text
b
the code you wrote uses internal id numbers
d
so use getText
Also before the script can run i get the mandatory error that the service item needs to be selected
b
i personally would recommend doing a search to get the correct internal id
you also want to consider a client script to do your logic in the ui
d
my goal was to use a fieldchanged event to see when the employee field was selected, then get the billingclass and set the billing class to the service item.
would that be the better approach
All this logic should be while an employee is filling our a time record.
executed*
b
client script if its for the user interface
d
ok i will try that