---
title: "Sample Groovy scripts for asset management in Jira workflows"
canonical: "https://support.appfire.com/space/AIP/10256592/Sample%20Groovy%20scripts%20for%20asset%20management%20in%20Jira%20workflows"
format: markdown
---
> Macro (aura-html)

This page provides Groovy script examples to interact with asset custom fields and Jira issues within your Jira workflows. These scripts can be used in post functions to update asset attributes based on Jira issue transitions.

> ✅ You can directly use `issue` or `originalIssue` of the transition, or fetch an issue by key or ID with Issue Manager (like `anotherIssue` in examples). `return` statements are optional but it makes the script more readable.

### Get Asset's Attribute value

<details>
<summary>Script:</summary>

```
return aipUtils.getAttributeValueAsStringByName(asset, 'Quantity');
```

**Example result:** 40
</details>

### Get Asset's Multiple Value Attribute values by name as List

<details>
<summary>Script:</summary>

```
import inventoryplugin.entity.JipInventoryItem;
import org.apache.commons.lang3.StringUtils;

String getMultipleValues() {
    def result = '';
    def cityList = aipUtils.getMultiAttributeValueAsListByName(asset, 'Cities ListBox Multiple');
  	for (String city : cityList) {
      result += city + ', '
    }
    return result;
}
return getMultipleValues();
```

**Example result:** New York, London,
</details>

### Get Asset's Multiple Value Attribute values by ID as List

<details>
<summary>Script:</summary>

```
import inventoryplugin.entity.JipInventoryItem;
import org.apache.commons.lang3.StringUtils;

String getMultipleValues() {
    def result = '';
    def cityList = aipUtils.getMultiAttributeValueAsListById(asset, 63);
  	for (String city : cityList) {
      result += city + ', '
    }
    return result;
}

return getMultipleValues();
```

Example result: New York, London,
</details>

### Get Asset's Attribute values by asset object in a loop

<details>
<summary>Script:</summary>

```
import inventoryplugin.entity.JipInventory
import inventoryplugin.entity.JipInventoryItem

def result = ""
result = result + "\n" + "Asset name: " + asset.getName()
result = result + "\n" + "Form name: " + asset.getForm().getFormName()
result = result + "\n" + "Attachments details: " + asset.getAttachments()
result = result + "\n" + "Creator: " + asset.getCreator()
result = result + "\n" + "Create time: " + asset.getCreated()

// attributes of asset
for(JipInventoryItem inventoryItem: asset.getInventoryItems()){
  // For the demo, we append all values to the Text area, so we skip TextArea attribute type values.
  if(inventoryItem.getFormAttribute().getAttribute().getAttributeType() != 'TextArea'){
    result = result + "\n" + inventoryItem.getFormAttribute().getAttribute().getAttributeName() + 
      ": " + inventoryItem.getValue()
  }
}

return issue.description + "\n" + result
```
</details>


<details>
<summary>Result:</summary>

```
*Creating Quick Filters* You can add your own Quick Filters in the board configuration (select *Board > Configure*)

Asset name: My second asset 001
Form name: All type of attributes form
Attachments details: [ {
    "originalFileName" : "arizona-asphalt-beautiful-490466.jpg",
    "serverFileName" : "51408_08610_1546431401755.jpg",
    "fileSize" : "1 MB",
    "created" : "02/Jan/19 2:16 PM",
    "creator" : "admin"
} ]
Creator: admin
Create time: 2018-12-11 13:30:05.124
 
Attribute name: field value
----------------------------------
CheckboxList Field: bal
City: izm
Cities: ist, ada
RadioCities: ist
InventoryList (All Assets List): 3
InventoryListByForm (Assets List By Form(s)): 10
City as DropdownList Field: ada
Purchase Date: 02.01.19
Assign DateTime: 02.01.19 15:16
Device IP: 10.0.0.2
Device IPv6: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Some Free Text: As a user, I can find important items on the board by using the customisable "Quick Filters" above >> Try clicking the "Only My Issues" Quick Filter above
A great URL example: http://www.snapbytes.com/
Assigned User: admin(admin)
```
</details>

### Get "Text Field" JIRA custom field value

<details>
<summary>Script:</summary>

```
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11000")
def cFieldValue = issue.getCustomFieldValue(cField).getValue()
  
return cFieldValue
```

**Example result: **Los Angeles
</details>

### Get "Select List (single choice)" or "<span style="color: #172b4d">Radio Buttons</span>" JIRA custom field value

<details>
<summary>Script:</summary>

```
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11000")
def cFieldValue = issue.getCustomFieldValue(cField).getValue()
  
return cFieldValue
```

**Example result: **Los Angeles
</details>

### Get "<span style="color: #172b4d">Select List (multiple choices)"</span> or "<span style="color: #172b4d">Checkboxes" </span>JIRA custom field values

<details>
<summary>Script:</summary>

```
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11001")
def cFieldValue = issue.getCustomFieldValue(cField)

def cityNameList = new ArrayList<String>()
for(String cityName: cFieldValue){
    cityNameList.add(cityName)
}
return String.join(", ", cityNameList)
```

**Example result:** Los Angeles, San Francisco, İstanbul
</details>

<span style="color: #172b4d">You can directly use </span>`issue`<span style="color: #172b4d"> or </span>`originalIssue`<span style="color: #172b4d"> of the transition, or get another issue with IssueManager (like the example below).</span>

```
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
 
def anotherIssue = ComponentAccessor.getIssueManager().getIssueObject("AP-5");
 
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_11001")
def cFieldValue = anotherIssue.getCustomFieldValue(cField)

def cityNameList = new ArrayList<String>()
for(String cityName: cFieldValue){
    cityNameList.add(cityName)
}
return String.join(", ", cityNameList)
```

<span style="color: #172b4d"> </span>**Example result:** <span style="color: #172b4d">Los Angeles, San Francisco</span>

### Get old and new status name of transitioned issue

<details>
<summary>Script:</summary>

```
return originalIssue.getStatus().getSimpleStatus().getName() + " -> " + issue.getStatus().getSimpleStatus().getName()
```

**Example result: **To Do -> In Progress
</details>

### Get resolution of transitioned issue

> 📝 <span style="color: #172b4d">Please note that </span>`getResolution`<span style="color: #172b4d"> may be null for unresolved issues. </span>

<details>
<summary>Script:</summary>

```
return issue.getResolution() != null ? issue.getResolution().getName(): "Not resolved"
```

**Example result: **Done
</details>

### Get resolution of another issue

> 📝 Please note that `getResolution` may be null for unresolved issues.

<details>
<summary>Script:</summary>

```
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def anotherIssue = ComponentAccessor.getIssueManager().getIssueObject("SB-146")
return anotherIssue.getResolution() != null ? anotherIssue.getResolution().getName(): "Not resolved"

```

**Example result: **Done
</details>

### Get Created/Updated Date of an issue

If you want to assign a `date` or `dateTime` asset attribute, the value must be in ISO time format (for example, `2018-11-06T10:24:37.513`).

- For Date-Time fields, `second` and rest of the value will be purged automatically. Result example: `2018-11-06T10:24`.
- For date fields, `minute` and rest of the value will be  purged automatically. Result example: `2018-11-06`.

<details>
<summary>Script:</summary>

```
import java.time.*  
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def anotherIssue = ComponentAccessor.getIssueManager().getIssueObject("SB-146")
return anotherIssue.getCreated().toLocalDateTime().toString()   // or use getUpdated insted of getCreated
```

**Example result:** 2018-11-06T10:24:37.513
</details>

### Get Reporter/Assignee user name of an issue

If you want to assign a `date` or `dateTime` asset attribute, the value must be in ISO time format (for example, `2018-11-06T10:24:37.513`).

- For Date-Time fields, `second` and rest of the value will be purged automatically. Result example: `2018-11-06T10:24`.
- For date fields, `minute` and the rest of the value will be purged automatically. Result example: `2018-11-06`.

<details>
<summary>Script:</summary>

```
import java.time.*  
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor

def anotherIssue = ComponentAccessor.getIssueManager().getIssueObject("SB-146")
return anotherIssue.reporter.username // or "anotherIssue.assignee.username"
```

**Example result:** marla
</details>

### Get Current datetime

If you want to assign a `date` or `dateTime` asset attribute, the value must be in ISO time format (for example, `2018-11-06T10:24:37.513`).

- For Date-Time fields, `second` and the rest of the value will be purged automatically. Result example: `2018-11-06T10:24`.
- For date fields, `minute` and the rest of the value will be purged automatically. Result example: `2018-11-06`.

<details>
<summary>Script:</summary>

```
import java.time.*
  
  LocalDateTime t = LocalDateTime.now();
  return (t as String)
```

**Example result:** 2019-01-07T17:03:43.767
</details>