Modifying script for UI Action "Copy from previous time sheet"

Jeff Krueger1
Tera Expert

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!

1 ACCEPTED SOLUTION

The SN Nerd
Giga Sage
Giga Sage

It would be best to preserve the OOB Script "TimeSheet".



The Best Practice approach would be to:




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

View solution in original post

4 REPLIES 4

Dale Hynes
Kilo Sage

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.


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!  


The SN Nerd
Giga Sage
Giga Sage

It would be best to preserve the OOB Script "TimeSheet".



The Best Practice approach would be to:




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

Thank you Paul, excellent advice!   Much appreciated.