Allow Multiple Time Cards for Each Category

jmpierce_prot
Giga Expert

My organization has a use case for needing several non-task time cards to be created for the same category.  For example, we've added a field to the time_card table that is a reference back to core_company.  This will allow our employees to track time to specific clients without a ticket.  Example: I have a meeting with a client and want to make sure my time is logged to that client.

 

I've added the field to the time sheet portal, and it's displaying the company without issue.  I can create a time card for the "Meeting" category and select the appropriate client.  However, when I click the "Add to Time Sheet" link on the "Meeting" category again for a new client, the time sheet portal wants to use the existing time card instead of creating a new one.  Is there a way to change the qualifier for what ServiceNow considers a duplicate time card?

 

I can add a new time card tracked to that category through the classic UI, but not the portal (which flags the time cards as duplicates).

 

This image should help illustrate the issue.

jmpierce_prot_0-1682777047633.png

 

Thank you!

1 ACCEPTED SOLUTION

jmpierce_prot
Giga Expert

In case anyone stumbles across this use case in the future, I was able to make some adjustments to meet my needs.  I don't consider making changes to core script includes or portal widgets ideal (for a variety of reasons), but this seemed like my only option.  If anyone from ServiceNow reads this, the ability to make these adjustments through configuration and not code would be great.

 

  • Add the field to the Time Card Portal Container (Widget Instance) in the Additional options, JSON format field.
  • Modify the copyTimeCard method in the TimeSheet script include.  Specifically, I added my field (u_company) to the fieldsToCopy list.  This allows time cards copied from another time sheet to carry over the custom field.
  • Modify the getTimeCardFilter method in the TimeCardUtil script include to include my custom field in the query that checks for duplicates.
  • Modify the highlightDuplicates method in the Time Card Grid Widget to add my custom field value to the uniqueItemKey variable.  This will prevent the time cards as being flagged as duplicates.

 

With these modifications, I'm able to see the company in the Time Sheet Portal grid, add multiple time cards assigned to the same category with different companies, and copy the company values from previous time sheets/cards.

View solution in original post

9 REPLIES 9

jmpierce_prot
Giga Expert

In case anyone stumbles across this use case in the future, I was able to make some adjustments to meet my needs.  I don't consider making changes to core script includes or portal widgets ideal (for a variety of reasons), but this seemed like my only option.  If anyone from ServiceNow reads this, the ability to make these adjustments through configuration and not code would be great.

 

  • Add the field to the Time Card Portal Container (Widget Instance) in the Additional options, JSON format field.
  • Modify the copyTimeCard method in the TimeSheet script include.  Specifically, I added my field (u_company) to the fieldsToCopy list.  This allows time cards copied from another time sheet to carry over the custom field.
  • Modify the getTimeCardFilter method in the TimeCardUtil script include to include my custom field in the query that checks for duplicates.
  • Modify the highlightDuplicates method in the Time Card Grid Widget to add my custom field value to the uniqueItemKey variable.  This will prevent the time cards as being flagged as duplicates.

 

With these modifications, I'm able to see the company in the Time Sheet Portal grid, add multiple time cards assigned to the same category with different companies, and copy the company values from previous time sheets/cards.

I implemented the solution described and technically it is doing what I need.  However, logging shows that my additional field (u_subcategory) value is always being returned as "undefined" even though it is defined in the Time Card Portal Container Widget Instance as follows ...

{
"tm_grid_options": {
"displayValue": "Time card grid options",
"value": {
"pageSize": 10,
"header_fields": [
{
"name": "task.short_description",
"width_in_percent": 16
},
{
"name": "category",
"width_in_percent": 10
},
{
"name": "u_subcategory",
"label": "Subcategory",
"width_in_percent": 10
}
]
}
}
}

Community Alums
Not applicable

Can you provide the update set so I can see how you modified the widget. 

@jmpierce_prot ,Would you mind sharing the step by step procedures for this? I have a requirement to let multiple KTLO entries to be added under time sheet. 

 

-Thanks in advance