Setting the "Generate Time Cards" button to include Incidents

robert_price
Giga Contributor

As part of our move to the ServiceNow Project Management system, we've been asked to change the Generate Time Cards button on my_timecards.do so that it generates time cards for the open incidents a user is either assigned to or on the watch list for.

To do this, I believe I would need to change the TimecardAjax script include so that it also queries for open incident tickets. However, I'm not entirely sure where to add that in the script, or if this will have negative effects when we try to upgrade.

My best bet is that I should add it as an additional query under the function "_getPlannedTasks", I don't want to change that function to search the Tasks table instead of the Planned Tasks table, even though that would solve the problem, as that would remove the "planned start" and "planned end" parts of the query, and would result in the query taking a *lot* longer. Is there an easy way to join this query with a query to the Incident table instead--or can I just add two GlideRecord objects together to make one larger one, thus combining records from both queries?

Is there any immediate negative to altering this OOB script?

I've posted "getPlannedTasks" below to make what I'm talking about a little more clear.

      _getPlannedTasks: function(){

  if (this.user == "")

                  return;

              var tasks = new GlideRecord("planned_task");

              tasks.addQuery("assigned_to", this.user);

  tasks.addOrCondition("watch_list", 'contains', this.user);

              tasks.addQuery("planned_start", "<=", this.weekEnd);

              tasks.addQuery("planned_end", ">=", this.weekStart);

              tasks.query();

              return tasks;

      },

1 ACCEPTED SOLUTION

robert_price
Giga Contributor

Turns out, the best solution was to add a new _getIncidents() function, and repeat the _generateMissingCards() function call in _generateTaskCards() on the results from getIncidents(). I was initially afraid that this would prevent the script include from building the time card tickets from _getProjectTasks(), but that appears to not have been the case.


View solution in original post

4 REPLIES 4

robert_price
Giga Contributor

Turns out, the best solution was to add a new _getIncidents() function, and repeat the _generateMissingCards() function call in _generateTaskCards() on the results from getIncidents(). I was initially afraid that this would prevent the script include from building the time card tickets from _getProjectTasks(), but that appears to not have been the case.


Ok, not to sound ignorant, but where is this? We are having an issue where when users click the Generate time card button, that it is generating cards against old projects and other SDLC items where a "placeholder" card was created simply because they touched the record by assigning it out to someone. We are looking to disable this button.


The generate time cards button (and the page itself) is on my_timecards.do, which you can find under the Content Management section marked 'Pages" or by typing my_timecards.do into the application menu search bar on the left.



However, it sounds like what you're looking for is the script behind the button. That's in the Script Includes section, and is called TimecardAjax. Its all in Ajax, but its otherwise pretty easy to modify, and it should tell you why the script might be generating off of placeholder cards.


Hi,



Is there a way to modify the TimecardAjax to auto generate time cards for "Admin" and "KTLO" when the "Generate Time Cards" button is clicked?



Thanks,
Todd