# How to get current JobId

**URL:** <https://discuss.hangfire.io/t/how-to-get-current-jobid/1703>\
**Category:** question\
**Tags:** sql-server, queues\
**Created:** [January 15, 2016, 12:34pm UTC](https://discuss.hangfire.io/t/how-to-get-current-jobid/1703 "2016-01-15T12:34:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarceloJunior](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/marcelojunior/32/505_2.png) [@MarceloJunior](https://discuss.hangfire.io/u/MarceloJunior)\
**Post date:** [January 15, 2016, 12:34pm UTC](https://discuss.hangfire.io/t/how-to-get-current-jobid/1703/1 "2016-01-15T12:34:23Z")

</div>

I try to find a solution to insert a custom history in a Job during the process, but I not found.

Then I want to create a log generator to a job process inserting directly in State table. For to do this, is necessary pass JobId. So, how can I get current JobId?

```
BackgroundJob.Enqueue(() => this.ProcessReport( Report.Id, Param));

...

public override void ProcessReport(long ReportId, Dictionary<string, object> Params)
{
    // Some things....

    Hangfire.InsertHistory(JobId, Reason, Data); // <-- Here. There is how get current JobId?

    // Some more stuff...
}
```

---

<div class="post-metadata">

**Author:** ![vip\_bit](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/vip_bit/32/78_2.png) [@vip\_bit](https://discuss.hangfire.io/u/vip_bit)\
**Post date:** [January 25, 2016, 9:22pm UTC](https://discuss.hangfire.io/t/how-to-get-current-jobid/1703/2 "2016-01-25T21:22:20Z")

</div>

[http://hangfire.discourse.group/t/how-to-get-jobid-within-job/851/3](http://hangfire.discourse.group/t/how-to-get-jobid-within-job/851/3)

---

<div class="post-metadata">

**Author:** ![burningice](https://dub1.discourse-cdn.com/flex017/user_avatar/discuss.hangfire.io/burningice/32/53_2.png) [@burningice](https://discuss.hangfire.io/u/burningice)\
**Post date:** [January 28, 2016, 4:01pm UTC](https://discuss.hangfire.io/t/how-to-get-current-jobid/1703/3 "2016-01-28T16:01:17Z")

</div>

Look at this thread which explains how you can store the JobId in a Static Thread Variable

[http://hangfire.discourse.group/t/how-to-get-jobid-within-job/851/5?u=burningice](http://hangfire.discourse.group/t/how-to-get-jobid-within-job/851/5?u=burningice)
