Forums

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

can a question be restricted to a space

dosjots
April 28, 2016
 

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Piyush A (STR)
Community Champion
March 17, 2022

Hi,

Below might help you to updates another CF select field value. Maybe you can make changes to it.  

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

// the name of the custom field (single select list type)
final cf_blocked_name = 'Blocked'
final cf_blockedR_name = 'Blocked Reason'
//copy the same for your additional field

// the value of the new option to set

Issue issue = event.issue
def issueKey = issue.key

def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def cf_blocked = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(cf_blocked_name)
assert cf_blocked: "Could not find custom field with name $cf_blocked"

def cf_blockedR = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(cf_blockedR_name)
assert cf_blockedR: "Could not find custom field with name $customFieldNameB"

if(issue.getCustomFieldValue(cf_blocked).toString() == 'No' && issue.getCustomFieldValue(cf_blockedR) == null ){
//def userCf = customFieldManager.getCustomFieldObjectByName("user picker")
issue.setCustomFieldValue(cf_blockedR,"")
//cf_blockedR.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf_blockedR), ""), new DefaultIssueChangeHolder())
issueManafer.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}  

 

 

Event: Issue Created and Issue Updated 

John Diaz
March 17, 2022

@Piyush A (STR) I was actually able to find an alternative way to do this and it was an oversight on my end once I figured it out.  I'm using the Dynamic Forms add-on which allows me to show fields based on the option selected from another field.  What I noticed was when I flip the Blocked Reason back to No, it removes the fields from showing up and actually wipes the data causing a reset in case I need to flip it back to Yes. 

However, this could be used for other use cases so I'll save this for now.  

Like Piyush A (STR) likes this
TAGS
AUG Leaders

Atlassian Community Events