- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 03:57 PM
Our instance is running on Istanbul, upgraded from Helsinki a couple of months ago. We currently have Time Sheets disabled as we did a significant amount of configurations to Time Cards for the type of functionality we needed in our organization. We are now wanting to use Time Sheets, but there are a few issues I have not been able to find a solution to.
The UI Action "Copy from previous time sheet" launches a dialog window which calls the UI Page "copy_time_sheet" and lets the user select a time sheet to copy from, and whether or not they'd like to copy the time that was logged in the cards associated with that sheet. However, the action copies the cards with the "Category" field populated, but does not carry across our custom added fields "Subcategory" or "Project Name".
How can I modify the script that performs the action to ensure those fields get added as well?
The processing script on the "copy_time_sheet" UI page is:
if (cancelled == "false") {
var shouldCopyTime = request.getParameter('copyTime') == 'on';
var previousTimeSheetId = previousTimeSheet;
var timesheet = new TimeSheet(timesheet_id);
timesheet.copyFromPreviousTimeSheet(previousTimeSheetId, shouldCopyTime);
var urlOnStack = GlideSession.get().getStack().bottom();
response.sendRedirect(urlOnStack);
}
I'm lost as to where to look from here... is the action coming from "timesheet.copyFromPreviousTimeSheet", and if so, can this be modified.... where is it? Any help would be greatly appreciated!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 06:11 PM
It would be best to preserve the OOB Script "TimeSheet".
The Best Practice approach would be to:
- Create a new Script Include that extends TimeSheet (e.g. CustomTimeSheet)
- Override the function "copyTimeCard" to include your custom fields
- Copy the OOB UI Page with your custom page and use that instead
- Use your extended Class in place of the OOTB one (var timesheet = new CustomTimeSheet(timesheet_id) );
This will preserve the UI Page (if new feature are added, you can revert) and TimeSheet function in future upgrades,
All changes to TimeSheet (except the function you override) will automatically be applied to your TimeSheet code.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 05:19 PM
Lines 4 and 5 in the processing script show it calling a Script Include (SI) named 'timesheet' and the specific function in that SI 'copyFromPreviousTimeSheet'.
Looking in the SI, the function determines what type of tasks are related to the timesheet etc then on Line 205 it calls out to another function 'copyTimeCard' (starts on Line 211) that has an array of 'fieldsToCopy'. Start by adding in your custom fields there and see what happens.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2017 07:04 AM
Thank you Dale! I don't know how I missed it yesterday as I'm sure I looked in the SI for TimeSheet but sure enough, there it was when I looked again after reading your response!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2017 06:11 PM
It would be best to preserve the OOB Script "TimeSheet".
The Best Practice approach would be to:
- Create a new Script Include that extends TimeSheet (e.g. CustomTimeSheet)
- Override the function "copyTimeCard" to include your custom fields
- Copy the OOB UI Page with your custom page and use that instead
- Use your extended Class in place of the OOTB one (var timesheet = new CustomTimeSheet(timesheet_id) );
This will preserve the UI Page (if new feature are added, you can revert) and TimeSheet function in future upgrades,
All changes to TimeSheet (except the function you override) will automatically be applied to your TimeSheet code.
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2017 07:05 AM
Thank you Paul, excellent advice! Much appreciated.