Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How Get customfield value without selecting any issue

Alik
Contributor
January 16, 2020

Hi all, I want to get custom field value with script runner, but without mentioning any information about issue key. I am only want to mention project name. It is possible to find exactly which mentioned field are changed and have counter for it? For example I have date custom fields(D1 and D2) and I glad to know which custom field are modified and which kind of new value that receive. I write simplified script that is not cover for my project. Please help :)  Thanks in advance.

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.IssueManager

IssueManager issueManager = ComponentAccessor.getIssueManager();

def issue = issueManager.getIssueObject("TEST-3");

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def changeItems = changeHistoryManager.getAllChangeItems(issue)

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10500");// here replace the ID with ID of your custom field.

def value = (String)issue.getCustomFieldValue(customField);

if(customField != null) {

        issue.getCustomFieldValue(customField);

    def userUtil = ComponentAccessor.getUserUtil()

    def last_change = changeItems.sort(false).last()

    def text1 = "LAST MODIFIED FIELD:"+ last_change["field"]+ "; FROM VALUE:"+ last_change["fromValue"] + "; TO VALUE:"+ last_change["toValue"]

    return text1;

} else {

     return "NO CHANGES"

1 answer

1 vote
Nic Brough -Adaptavist-
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.
January 20, 2020

Custom fields have no existence outside the issues that they belong to.

So the short answer here is "no", because you need to read the fields that belong to issues.

But, your question does suggest that you are interested in generalised information rather than issue-specific info.  I am a bit stuck because I don't know quite what you want.  Could you describe the reporting you want to give to your people?  Forget the tech and code for a sec, just describe the question your people want answered?

Alik
Contributor
January 20, 2020

Hi @Nic Brough -Adaptavist- , thanks for answer. 

1. Can I search issues for which a date field has been overwritten? For example I have "XX" date picker custom field and I want to see all issues where my field has been changed.

2. Second question, is it possible to have a counter to know how often the date has been changed?

Nic Brough -Adaptavist-
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.
January 21, 2020

You would need a new JQL function to do that.  The data about changes is in the issue history, but off-the-shelf JQL does not read it.

Similarly for the counter although you have more options

  • You could do it manually with a custom field and then a listener that caught any issue update and looked to see if the date had changed, adding one to the counter.
  • You could do it with a scripted field, one that looked at the issue counter and added up the number of changes of date
Alik
Contributor
January 23, 2020

Suggest an answer

Log in or Sign up to answer