---
title: "Asset generic Groovy script"
canonical: "https://support.appfire.com/space/AIP/10256617/Asset%20generic%20Groovy%20script"
format: markdown
---
> Macro (aura-html)

This guide explains how to use the **[AIP] - Asset generic Groovy script post **function to update asset objects when an issue transitions in your Jira workflow.

### Add post function

1. Navigate to your desired workflow in Jira.
2. Locate the **Post Function** section.
3. Add a new post function named **[AIP] - Asset generic Groovy script**.

> ✅ The Groovy script runs only once (not for each asset). All the matching custom fields with asset objects are passed to the post function as a context parameter.

4. Use the provided Groovy script editor to write your custom logic for updating the asset(s). Refer to the [Sample Groovy scripts](https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256622) for examples.
5. Put the post function in the middle after *Issue Updates* and before *GenerateChangeHistoryFunction* and *Re-index* post functions.

### Script context parameters

The script has access to several variables containing information about the issue and assets:

| **Parameter** | **Description** |
| --- | --- |
| Asset custom fields (with values) to inject as script parameter | Select the asset custom fields to inject as script parameters. Leave it blank to include all asset custom fields.<br>See context parameters for more information. |
| Groovy script | This is the script to be executed. |

### Context parameters for Groovy scripts

> ✅ Refer to [Sample Groovy scripts for asset management in Jira workflows](https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256592) for more examples.

| **Variable Name** | **Description** |
| --- | --- |
| `assetCustomFieldAndValueList` | List of custom fields with values. Its type is `List<AssetCustomFieldAndValue>`.<br>See [https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256711](https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256711) and [https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256622](https://appfire.atlassian.net/wiki/spaces/AIP/pages/10256622)  for examples. |
| `issue` | Access current issue. Instance of `com.atlassian.jira.issue.Issue`. See the [Atlassian documentation](https://docs.atlassian.com/software/jira/docs/api/9.14.0/index.html?com/atlassian/jira/issue/Issue.html) for more details. |
| `originalIssue` | Access original issue before the transition. Instance of `com.atlassian.jira.issue.Issue`. See the [Atlassian documentation](https://docs.atlassian.com/software/jira/docs/api/latest/index.html?com/atlassian/jira/issue/Issue.html) for more details. |
| `ComponentAccessor` | Access Jira components. See the [Atlassian documentation](https://docs.atlassian.com/software/jira/docs/api/latest/index.html?com/atlassian/jira/component/ComponentAccessor.html). |
| `customFieldManager` | Access Jira Custom Field Manager class. See the [Atlassian documentation](https://docs.atlassian.com/software/jira/docs/api/latest/index.html?com/atlassian/jira/issue/CustomFieldManager.html). |
| `loggedInUser` | ApplicationUser instance for the currently logged-in user. See the [Atlassian documentation](https://docs.atlassian.com/software/jira/docs/api/latest/index.html?com/atlassian/jira/user/ApplicationUser.html).<br>**Example: **`loggedInUser == issue.getAssignee()` |
| `DefaultIssueChangeHolder` | Default implementation of a change holder. It is used to update a custom field. |
| `aipUtils` | Helper class for the post function Groovy script. See [aipUtils](https://appfire.atlassian.net/l/cp/PxxRXGVh) for details. |

### Try Groovy scripts

You can immediately execute a Groovy script to see the result. This will let you write and try your Groovy scripts faster. 

> ⚠️ **The scripts will be actually executed**; if you modify anything, please use test objects (issue, asset, etc.).