Using Effective Dating with Employee Workflows and SuiteScripts
You can make past, future, or current-day changes to the employee record using the user interface and using workflows and SuiteScripts. When you make an effective-dated change to the employee record, you specify a change reason. When you make past or future effective-dated changes, you also specify the effective date for the change.
Current Day Changes
Here is a sample of how you make changes to today’s version of the employee record:
require(['N/record'], function (record) {
var rec = record.load({type: 'employee', id: '659'});
rec.setValue({fieldId: 'initials', value: 'CC'});
rec.setValue({fieldId: 'employeechangereason', value: '4'});
rec.save({ignoreMandatoryFields: true});
});
Future or Past Effective-Dated Changes
Here is a sample of how you make changes to the employee record on a future or past date:
define(['N/record','N/format'], function(record, format) {
function onRequest(){
var loadDate = format.parse({value: "14/11/2021", type: format.Type.DATE});
var rec = record.load({type: "employee", id: '2730', defaultValues: {effectivedate: "14/11/2021"}}); // or customers date format in this case, mm/dd/yyyy
rec.setValue({fieldId: "title", value: "Manager"});
rec.setValue({fieldId: "effectivedate", value: loadDate});
rec.save({ignoreMandatoryFields: true});
};
return {
onRequest : onRequest
}
});
The effectivedate field syntax must match the format you have chosen in your company settings. Go to Setup > Company > Preferences > General Preferences to configure your Date Format. Confirm that any SuiteScripts or workflows that reference the effectivedate field are using the same format.