> For the complete documentation index, see [llms.txt](https://docs.work-relay.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.work-relay.com/automations/best-practices-screensteps/working-with-step-dynamic-duration-process-level.md).

# Working with step dynamic duration (process level)

User can set task duration using Data Source and Context Objects fields so that duration is calculated on the fly when process instance is created.

Below is example of using dynamic durations approach within process builder.

{% hint style="info" %}
While constructing expressions to put into "Duration" input please keep in mind that after all calculations and formatting step duration should have following format: \[1d 1h 1m].
{% endhint %}

{% hint style="info" %}
Duration calculations are performed based on the business hours record defined in [Work Relay Settings](/administration/settings/work-relay-settings.md).
{% endhint %}

For more information on Work Relay Business Hours please refer to the following article [Work Relay Business Hours](/administration/work-relay-data/business-hours.md).

## Setting duration using data source object

Click on "Duration" field (1) to show "f(x)" link (2). Click on link to open "Edit Duration Formula" popup (3). Choose a Data Source numeric field. Apply it into Duration input for a step (4) with added time indicator (h/d/m) (5).

![](/files/3c2cdf82907b81bbb3e630b39d2de52f8c959aba)

Given **HoursPerDay\_\_c** value is 9. When the process instance is created step duration will be set to **9h**.

{% hint style="info" %}
If time indicator was not added (e.g. final duration value was plain "`{Account.HoursPerDay__c}`") the system would consider duration has been provided using days. In other words if one did not add **h** indicator to above duration setting system would set duration to **9d** once process was started.
{% endhint %}

## Setting durations using calculations

Choose a Data Source numeric field. Select Context Object numeric field. Construct expression to put into Duration input.

![](/files/5863472097d9015acd7d28acf8226e7fc2c55a5a)

Above setting will multiply **HoursPerDay\_\_c** value by **DaysNumber** and as time indicator was not specified system will consider the result as days number. So if **HoursPerDay** is 8 and **DaysNumber** is 10 then duration will be saved as **80d** once the process is started.

{% hint style="info" %}
For any calculations within duration input use FORMULA context in a following way: FORMULA\[expression to get duration]
{% endhint %}

For more information about context objects properties please refer to following article: [Working with Work-Relay Context Objects](/automations/queries-and-conditions/working-with-work-relay-context-objects.md)

{% hint style="info" %}
Within FORMULA context you can use all functions available in process builder, to get information on Work Relay functions please refer to the following article: [Using Functions](/automations/functions-and-formulas/introduction-and-usage.md).
{% endhint %}

Also within formula context you can use mathematical operators ( + , -, \* eсt ).

## Formating durations

User can perform complex calculations using both static and dynamic duration values within single expression using formulas, especially proper functions:

* [TOTEXTDURATION()](/automations/functions-and-formulas/functions-library/text-functions.md#totextduration)
* [FROMTEXTDURATION()](/automations/functions-and-formulas/functions-library/text-functions.md#fromtextduration)

**Below is an example of using these formulas:**

Given one need to set duration as a sum of static and dynamic values, e.g. `5d + {Account.Minutes__c}` where `Minutes__c` stores integer representing number of minutes.

Actions that needs to be performed to get it work as expected:

{% stepper %}
{% step %}

## Convert static value into minutes

Use the **FROMTEXTDURATION** formula:

{% code overflow="wrap" %}

```apex
FROMTEXTDURATION(5d) + {Account.Minutes}
```

{% endcode %}

Given `{Account.Minutes}` is 30. Above expression will convert **5d** into integer representing number of minutes (**7200**) and add **30**, i.e. the result will be **7230**.
{% endstep %}

{% step %}

## Convert the result into a duration string

Convert 7230 into String of a format `[1d 1h 1m]` using **TOTEXTDURATION** formula:

{% code overflow="wrap" %}

```apex
TOTEXTDURATION(FROMTEXTDURATION(5d) + {Account.Minutes})
```

{% endcode %}
{% endstep %}

{% step %}

## Wrap the expression with FORMULA context

{% code overflow="wrap" %}

```apex
FORMULA[TOTEXTDURATION(FROMTEXTDURATION(5d)+ {Account.Minutes})]
```

{% endcode %}

Place above expression into Duration input. Once the process instance is created step duration will be set to **5d 30m**.
{% endstep %}
{% endstepper %}
