can any one help me out
i want to update timesheet weekof date field via script ,when i try to set the date of weekof via script it sets the current weekof but when i set date of weekof of last month manually it it able to set but cant set that via script. I want to set the weekof of last month via script.every response will appretiated
j
Jose Sanchez-Capo
01/16/2023, 2:25 PM
@Arham Momin In NetSuite, the timesheet "weekof" field is a read-only field, which means that it cannot be updated via script. The field is automatically populated based on the date of the timesheet.
However, you can achieve the same result by creating a new timesheet with the desired "weekof" date via script.
Jose Sanchez-Capo
01/16/2023, 2:25 PM
var timeSheet = nlapiCreateRecord('timesheet');
timeSheet.setFieldValue('employee', employeeId);
// set the desired "weekof" date
var weekofDate = nlapiAddMonths(nlapiDateToString(new Date()), -1);
timeSheet.setFieldValue('weekof', weekofDate);
// set other fields as needed
// ...
var timeSheetId = nlapiSubmitRecord(timeSheet);
Jose Sanchez-Capo
01/16/2023, 2:25 PM
In the above example, a new timesheet record is created and the "weekof" field is set to the date of last month. Keep in mind that the date should be passed in the format of string.
It's worth to mention that this will create a new timesheet with the "weekof" date you want, instead of updating an existing one.
a
Arham Momin
01/16/2023, 3:26 PM
sir very very thanks for response i ll sure try it
Arham Momin
01/16/2023, 3:29 PM
SIr above example is in 1.0 version ,i had code in 2.1 version ,is nlapiAddMonths works in 2.1
Arham Momin
01/16/2023, 3:39 PM
in your code sir you are passing date in string format ,if i pass my date in string format then it will set that date which i want to set