Forums

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

Update text field

Viktor Fedun June 25, 2024

Hi, why does update field value + update issue are not actually updating issue fields?
I have a script


 

import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def issue = issueManager.getIssueByCurrentKey("EQ-114892")
def customField = customFieldManager.getCustomFieldObject("customfield_24100") //text-field

if (issue && customField) {

    def changeHolder = new DefaultIssueChangeHolder();
    def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser;

    def customFieldValue = issue.getCustomFieldValue(customField)
    log.debug("The value of ${customField.getName()} for issue ${issue.getKey()} is: ${customFieldValue}") //any value allowed here, initial

    customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), null),changeHolder);
    issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
    customFieldValue = issue.getCustomFieldValue(customField)
    log.debug("The value of ${customField.getName()} for issue ${issue.getKey()} is: ${customFieldValue}") //should be null

    customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), "1234567"),changeHolder);
    issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
    customFieldValue = issue.getCustomFieldValue(customField)
    log.debug("The value of ${customField.getName()} for issue ${issue.getKey()} is: ${customFieldValue}") //should be 1234567

    customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), issue.getCustomFieldValue(customField) + "890"),changeHolder);
    issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
    customFieldValue = issue.getCustomFieldValue(customField)
    log.debug("The value of ${customField.getName()} for issue ${issue.getKey()} is: ${customFieldValue}") //should be 1234567890

}

but the results are 


 

2024-06-25 11:34:35,006 DEBUG [runner.ScriptBindingsManager]: The value of JSON for issue EQ-114892 is: 1234567890890890890890890890
2024-06-25 11:34:35,010 DEBUG [runner.ScriptBindingsManager]: The value of JSON for issue EQ-114892 is: 1234567890890890890890890890
2024-06-25 11:34:35,014 DEBUG [runner.ScriptBindingsManager]: The value of JSON for issue EQ-114892 is: 1234567890890890890890890890
2024-06-25 11:34:35,019 DEBUG [runner.ScriptBindingsManager]: The value of JSON for issue EQ-114892 is: 1234567890890890890890890890

1 answer

1 vote
Florian Bonniec
Community Champion
June 27, 2024

Hi @Viktor Fedun 

 

If the version of scriptrunner is recent I suggest you to use HAPI instead.

Update Fields (adaptavist.com)

 

Regards

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events