# Change before last workflow fail

**URL:** <https://community.temporal.io/t/change-before-last-workflow-fail/6107>\
**Category:** Community Support\
**Created:** [September 30, 2022, 4:12pm UTC](https://community.temporal.io/t/change-before-last-workflow-fail/6107 "2022-09-30T16:12:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dominik\_Labas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/dominik_labas/32/2827_2.png) [@Dominik\_Labas](https://community.temporal.io/u/Dominik_Labas)\
**Post date:** [September 30, 2022, 4:12pm UTC](https://community.temporal.io/t/change-before-last-workflow-fail/6107/1 "2022-09-30T16:12:25Z")

</div>

Hi, I am working on a temporal workflow that calls other services and want to use `RetryOptions` woth something like `setMaximumAttempts(4)`. After the last attempt, before the workflow fails completely without another retry, I would like to change an internal `status` value to my own failed status. Something like `status = WorkflowStatus.FAILED`, is there some nice way how I can do this, please?

---

<div class="post-metadata">

**Author:** ![antonio.perez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/antonio.perez/32/2417_2.png) [@antonio.perez](https://community.temporal.io/u/antonio.perez)\
**Post date:** [September 30, 2022, 4:35pm UTC](https://community.temporal.io/t/change-before-last-workflow-fail/6107/2 "2022-09-30T16:35:32Z")

</div>

Hello @Dominik_Labas

sorry, it is not clear to me if you are setting `setMaximumAttempts` to the workflow or the activity.

and can I ask what is your use case?

---

<div class="post-metadata">

**Author:** ![Dominik\_Labas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/dominik_labas/32/2827_2.png) [@Dominik\_Labas](https://community.temporal.io/u/Dominik_Labas)\
**Post date:** [October 3, 2022, 8:08am UTC](https://community.temporal.io/t/change-before-last-workflow-fail/6107/3 "2022-10-03T08:08:02Z")

</div>

Hi @antonio.perez,

thanks for the quick response. I wanted to set it for the workflow, but what I actually needed was to set it for the activity and catch `ActivityFailure`.

---

<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:** [October 3, 2022, 12:39pm UTC](https://community.temporal.io/t/change-before-last-workflow-fail/6107/4 "2022-10-03T12:39:15Z")

</div>

Yes ActivityFailure is delivered to your workflow code after all activity retries, similarly you can catch ChildWorkflowFailure for child workflow invocations inside your workflow code.

Note that you can also restrict the amount of retries via ActivityOptions-\>ScheduleToClose timeout. StartToClose is timeout for a single activity invocation, ScheduleToClose is timeout that includes all retries as well. Often ScheduleToClose can be more useful than setting max retries, see video [here](https://www.youtube.com/watch?v=JK7WLK3ZSu8).
