Update custom fields using using Atlassian SDK (.Net)

saurabh October 23, 2017

I added custom field on Jira server and I want to update that field using Atlassian SDK (.Net), I can not able to do this with right approach.

Could you please help me?

2 answers

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2017

You are going to need to explain what context your code is running in.

Is it an add-on for Server, and add-on for Cloud, an external program, or are you hacking the core of Jira?

0 votes
Tayyab Bashir
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2017

Hi,

You can look into JIRA APIs
The main one you can look into is ComponentAccessor. From here you can explore more methods that better suit your needs.

For example if you want to find something related to issue and customfields, then you can look into their APIs and methods. 

From ComponentAccessor you can navigate IssueManager Api and CustomFieldManager and explore them for your particular usage.

There are certain plugins as well like ScriptRunner that can help you add back-end code to a field and update it. 

For example you can access your custom field from a certain issue like this:

import com.atlassian.jira.component.ComponentAccessor

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

def issueObject = issueManager.getIssueObject("Issue-Key")

// Get your Custom Field by its ID
def customFieldObject = customFieldManager.getCustomFieldObject(customFieldID)


// Get All custom fields within a issue scope
def customFieldObjects = customFieldManager.getCustomFieldObjects(issueObject)

// See if your customfield is in the issue
// If it is, then do what you want with it.
if (customFieldObjects.contains(customFieldObject))
{
// Do your stuff with the field
}
 

 

saurabh October 23, 2017

Thank you for reply.

Actually I'm using Atlassian.SDK which supports for .Net Library.

I am able to fetch custom fields but stuck to update that field through code.

For example :

var temp = await JiraInstance.Fields.GetCustomFieldsAsync();

 

using this I can retrieve all custom fields for that project but how can i updated particular fields?

Could you please help me?

Tayyab Bashir
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 23, 2017

To update the customField you can use the updateValue method.

It takes in Fieldlayout, IssueObject, Modified Value (need to pass both old and new value) and IssueChagneHolder. 

You can try something as follows:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

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

// Get issueObject by key.
def issueObject = issueManager.getIssueObject("Issue-KEY")

// Get the CustomField by its ID
def customFieldObject = customFieldManager.getCustomFieldObject(10125)

// Get the current value of CustomField
def
oldValue = customFieldObject.getValue(issueObject)

// Create a new value to assign later on
String newValue = "New Value"

//Main method to update custom field.
changeHolder = new DefaultIssueChangeHolder()
customFieldObject.updateValue(null, issueObject, new ModifiedValue( oldValue, newValue), changeHolder)

As an example I was explicitly getting issue object based on key, you can change that to generalize it for all issue. 

Suggest an answer

Log in or Sign up to answer