# Possible to set ActivityId?

**URL:** <https://community.temporal.io/t/possible-to-set-activityid/3406>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [November 17, 2021, 9:20am UTC](https://community.temporal.io/t/possible-to-set-activityid/3406 "2021-11-17T09:20:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![darewreck](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@darewreck](https://community.temporal.io/u/darewreck)\
**Post date:** [November 17, 2021, 9:20am UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/1 "2021-11-17T09:20:24Z")

</div>

Hi,

I was wondering when you create the `ActivityStub` is there a reason why we can’t configure the `activityId` in the `ActivityOptions`. We are able to do it at the when creating a new workflow stub via `WorkflowOptions`. It seems natural that `ActivityOptions` should cover it as well.

Being able to set the `activityId` can be useful. For example, I generate activities in a cancel scope and rely on signals coming into the workflow to cancel the activity. In this case, the workflow contains an internal mapping between the cancel scope and some sort of ID associated with the activity. Since I don’t know the activity ID since I can’t set it in the Workflow scope, I’m forced to pass in a generated UUID into the activity method. This activity method will tell the external service this UUID so it can use it to signal the workflow to cancel the activity.

However, if i was able to set the activity ID when starting it, this will make this whole flow a lot easier.

Thanks,  
Derek

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 17, 2021, 2:53pm UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/2 "2021-11-17T14:53:21Z")

</div>

Activity Ids have to be unique in Java SDK because currently there is no way to specify it via ActivityOptions - see [Support passing activityId to an activity invocation · Issue #86 · temporalio/sdk-java · GitHub](https://github.com/temporalio/sdk-java/issues/86). Until this feature is added, the activity id is generated.  
You register a single activity impl with your workers, so each activity invocation uses that same instance (thus your activity code should be thread-safe :)).

You can get the activity id inside activity methods via:

`Activity.getExecutionContext().getInfo().getActivityId();`

if that helps.

Another idea is that since your activities that you want to cancel have to heartbeat, from outside of workflow you can use [DescribeWorkflowExecution](https://github.com/temporalio/sdk-go/blob/9778ef5e148d747e953dc88a8dd654d6074ad417/client/client.go#L334) call that returns all pending activities information including data included in the last heartbeat. This could help with your activities not to have to notify the external service directly.

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 17, 2021, 3:15pm UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/3 "2021-11-17T15:15:46Z")

</div>

Updated last response to add open issue [Support passing activityId to an activity invocation · Issue #86 · temporalio/sdk-java · GitHub](https://github.com/temporalio/sdk-java/issues/86)

---

<div class="post-metadata">

**Author:** ![darewreck](https://avatars.discourse-cdn.com/v4/letter/d/c37758/32.png) [@darewreck](https://community.temporal.io/u/darewreck)\
**Post date:** [November 17, 2021, 4:47pm UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/4 "2021-11-17T16:47:26Z")

</div>

@tihomir do you know if this will be actively addressed? If so, is there an eta? Looks like the request has been around for a while.

Thanks  
Derek

---

<div class="post-metadata">

**Author:** ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)\
**Post date:** [November 17, 2021, 5:11pm UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/5 "2021-11-17T17:11:51Z")

</div>

@spikhalskiy , any ideas? Sorry to put you on the spot 🙂

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [November 18, 2021, 3:52am UTC](https://community.temporal.io/t/possible-to-set-activityid/3406/6 "2021-11-18T03:52:10Z")

</div>

@darewreck I think the only valid use case for assigning Activity ID is to complete it asynchronously by the Workflow ID and Activity ID.

Your use case can be solved the way you described without relying on the explicit assignment of the Activity ID.
