Advice needed - Time tracking process on JSM
Asked by Berat Altunhan:

Hello,

<br />

I will explain what I want to do through a scenario. This scenario takes place on the Jira Service Management product.

*Company A is a consulting firm and sells packages to its customers over the hour. For example, it sells a 20-hour consulting package in May and the customer can get 20 hours of support from company A in May. Company A wants to keep the 20 hours of support on Jira, and when a request is received from each customer, it wants to enter the number of hours it solved these requests -time tracking- on Jira, subtract this from the total package received (20 hours) and send this information via an automatic mail when the job is "Done".*

<br />

How can I set up this process on Jira Service Management? I am waiting for your advice.


Answers:
author: Adaeze_Jude_HEROCODERS
body: Hello [@Berat Altunhan](/t5/user/viewprofilepage/user-id/5102331) ,

You can use [Clockwork](https://marketplace.atlassian.com/apps/1219213/clockwork-automated-time-tracking-timesheets-pro?hosting=cloud&tab=overview) API to automate this process using an automation rule.

First, I would advice a scenario where every customer is assigned a project.

The trigger for the automation should be when Work is logged. After this, a Web request is sent using Clockwork API that allows you to specify the ProjectKEY and the start time, as below:

```
https://api.clockwork.report/v1/worklogs?starting_at={{now.startOfMonth.jiraDate}}&project_key=HELP##)}}
```

the starttime specifies the beginning of each month so you can get the totaltimespent in seconds for that month

The webrequest should be as below:

![Grammarly.Desktop_YK6e5yN3Vf.png](https://community.atlassian.com/t5/image/serverpage/image-id/321493i1149730E527A51C9/image-size/large?v=v2&px=999 "Grammarly.Desktop_YK6e5yN3Vf.png")

Next, add an if/else condition. In the If condition, check that the webresponse status category is a success. Next, create a variable to save the sum on the webresponse.timepsent, as shown:

![chrome_4H8v4zqrtC.png](https://community.atlassian.com/t5/image/serverpage/image-id/321494i8B6B2CA8DA5BA70A/image-size/large?v=v2&px=999 "chrome_4H8v4zqrtC.png")

Next, create another variable to save time in hours as shown:

![chrome_lUGO4hQXdd.png](https://community.atlassian.com/t5/image/serverpage/image-id/321495i1CA00953595D1FAB/image-size/large?v=v2&px=999 "chrome_lUGO4hQXdd.png")

Next, create a variable to save the time left, this is ***in your case 20h-timespentHours***, as below:

![chrome_03DNXUTKAa.png](https://community.atlassian.com/t5/image/serverpage/image-id/321498i44B966A91E08DE44/image-size/large?v=v2&px=999 "chrome_03DNXUTKAa.png")

After identifying your variable, you can then add an action to send an email to a desired email address as below:

![chrome_iyemmunjfu.png](https://community.atlassian.com/t5/image/serverpage/image-id/321499i80605E6485C14467/image-size/large?v=v2&px=999 "chrome_iyemmunjfu.png")

To use this rule for more than one project, first, you can replace the web request as below:

```
https://api.clockwork.report/v1/worklogs?starting_at={{now.startOfMonth.jiraDate}}&project_key={{triggerIssue.key.substringBefore("-")}}


```

then for the email to be sent to different email addresses, create a custom field to store the email address of every customer on their respective issue and you can dynamically reference that email with {{triggerissue.\[Custom Field\].id}}.

Also, to avoid the rule from running every time a user logs time, you can change the trigger for this issue to be *scheduled*.

I will be happy to work with you on this, please reach out to us [here](https://herocoders.atlassian.net/servicedesk/customer/portals) if you have further questions.

comments: author: Wojciech Wardaszko _HeroCoders_
body: [@Adaeze_Jude_HEROCODERS](/t5/user/viewprofilepage/user-id/4978590) [@Berat Altunhan](/t5/user/viewprofilepage/user-id/5102331)

let's just add that to use our API you'd need to install either [Clockwork Free](https://marketplace.atlassian.com/apps/1220750/clockwork-automated-time-tracking-timesheets-free?hosting=cloud&tab=overview) or [Clockwork Pro.](https://marketplace.atlassian.com/apps/1219213/clockwork-automated-time-tracking-timesheets-pro?hosting=cloud&tab=overview)


Tags: cloud

community-leaders

jira-service-management

jira-service-management-cloud

leader

process

zzz