Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,458,283
Community Members
 
Community Events
176
Community Groups

How retrieve a value base when value selected from DB picker field?

Hi,

I created a DB picker field "Location Name" which displays all locations from a drop-down field. That is working fine, we are using it for multiple projects.

For a new project, we would like to do some automation. We would like to retrieve a person's name to a text field if a location is selected from the DB picker field. We have accounts from different locations and multiple locations are assigned to a person. for example, we have 5 Reps and each rep are assigned 10 locations. So when the user is creating an issue and selecting a location from the DB picker drop down it should add the person to the text field (Representative) that belongs to that location.

The below listener script works fine with Jira custom fields but it is not working with the DB picker field. I mean instead of DB picker if I use a text field and type that location name that exists in the database it'll pull up the rep name, but for some reason, it's not working with the ScriptRunner DB picker field.

Any idea how I can make it works?

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.db.DatabaseUtil
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def event = event as IssueEvent
def issue = event.issue
def customFieldObjects = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue)

def locationName = customFieldObjects.findByName("Location Name")
def rep = customFieldObjects.findByName("Representative")

def value = issue.getCustomFieldValue(locationName)

DatabaseUtil.withSql('Mysql_Accounts_DB') { sql ->
def row = sql.firstRow("""SELECT customer_id, LocationName, AssignedRepPerson, AssignedRep_id
FROM Accounts WHERE LocationName = ?""", value)
if (row) {

rep.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(rep), row.'AssignedRepPerson'), new DefaultIssueChangeHolder())
}
}

Thank you

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events