We have integrated an API for our app's elements, such as custom fields and relations. This page provides a collection of examples on how to modify or work with the data using scripts. For information about the scripting language itself and available functions and features please refer to the respective documentation. The following section will help you to set up your API requests.

Work with Assets data via REST

When using the REST API, you can access and modify STAGIL Assets fields in the same way you would do with other issue fields. When getting the data, you can use your REST call to get the issues data and see all related issues in the Assets custom field as issue keys:

STAGIL Assets also provides several custom field types. One of them gives you the ability to create QR or bar codes for your assets/issues. If you want to retrieve the images via the REST API, e.g. to use them somewhere else for printing, simply look out for your custom field ID in the body of the GET request, where you will find the path to the image. It will look like this:

GET Advanced Links Field Values via REST

You can retrieve the information contained in a relation custom field via the following two URLs, which will give you the same results:

URL 1: https://yourjiraURL.com/rest/soj/1.0/relationField/values/relation/{relationId}/{issueOutKey}/{issueInKey}

URL 2: https://yourjiraURL.com/rest/soj/1.0/relationField/values/{issueLinkTypeId}/{issueOutKey}/{issueInKey}

You will get the following response: {“relationFieldValues”: [{“name”: “Name of relation”, “id”: “10”, “type”: “text”, “valueStr”:”relation attribute(s)”}]

How to retrieve the issue link type ID?

Navigate to the issue graph with the relation which contains attribute(s). Active “Inspect Element” in your browser settings and click on the arrow in your graph that contains the attribute.

SIL (Simple Issue Language)

Using STAGIL Assets with SIL scripts is very simple. We have created a list to make it easier for you to get started:

Get the values of the Advanced Links

// Get the values for the outward field where the relation name equals "Relation" for issue PM-1
string[] keys = allLinkedIssues("PM-1","Relation", 1);

// Get the values for the inward field where the relation name equals "Relation" for issue PM-1
string[] keys = allLinkedIssues("PM-1","Relation", -1);

Add or remove issues from Advanced Links

// Add the issue PM-5 to the outward field for issue PM-1
linkIssue("PM-1", "PM-5", "Relation");

// Remove the issue PM-5 from the outward field for issue PM-1
unlinkIssue("PM-1", "PM-5", "Relation");

// Add the issue PM-5 to the inward field for issue PM-1
linkIssue("PM-5", "PM-1", "Relation");

// Remove the issue PM-5 from the inward field for issue PM-1
unlinkIssue("PM-5", "PM-1", "Relation");

// (!) You only need to create one issue link for the outward or inward field. The other one will be filled automatically.

Groovy

There is enough documentation about Groovy available, but we want to give you some advice on how to use the STAGIL Assets fields and data with Groovy to get you up to speed as quickly as possible.

Check, if custom field is a STAGIL Assets field

CustomField customField = customFieldManager.getCustomFieldObject(10101l);
def cft = customField.getCustomFieldType();
Collection<Issue> selectedIssues = null;

if(cft.getKey().equals("de.stagil.jira.stagil-assets:stagil-assets-relation") || cft.getKey().equals("de.stagil.jira.stagil-assets:stagil-assets-dynamic") || cft.getKey().equals("de.stagil.jira.stagil-assets:stagil-assets-picker")){
	return "This is a STAGIL Assets custom field."
}

Get the values of the linked issues of an Advanced Link

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.customfields.CustomFieldType;

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)

//Get the issue, where PM-1 should be replaced with your issue key
Issue issue  = issueManager.getIssueObject("PM-1");

//Get the custom field, where 10101 should be replaced by your custom field ID
CustomField customField = customFieldManager.getCustomFieldObject(10101);

def cft = customField.getCustomFieldType();
Collection<Issue> selectedIssues = null;

//Ignore the error that will be displayed for the following line
selectedIssues = cft.getLinkedIssuesList(customField, issue);

myLog.debug(selectedIssues)

Change/update linked issues of an Advanced Link

Refer to Get the values of the linked issues for information about the script, but for updating the links you need to transform the issue list to a string and update it by using

where A, B and C are the issue keys.