Update custom fields using using Atlassian SDK (.Net)

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 vote

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
}
 

 

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 Community Champion Oct 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. 

0 vote

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?

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot