Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

auto populate a custom field with exceptions

Deleted user Aug 14, 2017

Hi,

I want to populate custom fields with a specific value depending on a scripted field. 

Example: Custom field = A --> text field = A1

Custom field = B --> text field = fkdfm

I tried to do it with a post function in a transition, but if someone already writes another value in the text field, this value gets overwritte. Even when no value has been scripted in the scripted field, it gets all wiped out. 

So, I was thinking about a script listener, but I'm not that good of a coder. I'm stuck somewhere :-)

I'm doing something wrong here:



import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.event.type.EventDispatchOption

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

def customerField = customFieldManager.getCustomFieldObject("customfield_13102")
def customer = event.getIssue().getCustomFieldValue(customerField)

def serverName = ""

if(customer == "customerA"){
serverName = "customerA.server"
} else if(customer == "customerB"){
serverName = "customerB.server"
}

if(serverName != ""){
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def mutableIssue = issueManager.getIssueObject(event.getIssue().getKey())
mutableIssue.setserverName()

def updateIssueRequest = UpdateIssueRequest.builder().build()
updateIssueRequest.builder().eventDispatchOption(EventDispatchOption.ISSUE_UPDATED)
issueManager.updateIssue(applicationUser, mutableIssue, updateIssueRequest)
}

 

Any help is appreciated!

Kind regards,

Robin

1 answer

Your script is very close, though I am not sure what the setserverName() method is from. This script should work in a listener, just put in the name of your server name custom field:

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

def issue = event.issue as Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def customerField = customFieldManager.getCustomFieldObject("customfield_13102")
def customer = issue.getCustomFieldValue(customerField)

def serverName = ""

if(customer == "customerA"){
serverName = "customerA.server"
} else if(customer == "customerB"){
serverName = "customerB.server"
}

if(serverName != ""){
def serverField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Name of server field"}
def changeHolder = new DefaultIssueChangeHolder()
serverField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(serverField), serverName),changeHolder)
}
Deleted user Aug 16, 2017

Hi Joshua

Thank you for your reply.

I get an error when I do it like this.

Deleted user Aug 16, 2017

it flags the error as inappropriate, so I added screenshots.

2017-08-16 14_37_00-- Objectway Jira Test - Opera.png2017-08-16 14_37_10-- Objectway Jira Test - Opera.png

Could you post the script you're using? Did you change what gave you? It looks like you're trying to get the reporter of the issue to use for the customer variable.

Deleted user Aug 17, 2017

I just changed the name of the customer

 

import com.atlassian.jira.component.ComponentAccessor

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

def issue = event.issue as Issue

def customFieldManager = ComponentAccessor.getCustomFieldManager()

def customer = Issue.getReporter()

def serverName = ""

if(customer == "customerA"){
serverName = "server"
} else if(customer == "portfolio@customerA.com"){
serverName = "serverA"
}

if(serverName != ""){
def serverField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Environment (Server URL)"}
def changeHolder = new DefaultIssueChangeHolder()
serverField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(serverField), serverName),changeHolder)
}

Deleted user Aug 17, 2017

I see what you mean, I tried something else as well. I've tried it with the reporter, just to see if that would work...

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

81 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you