Forums

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

Set value of a Single User Picker based on value of a Single Select List

Michael Thompson
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 Champions.
July 15, 2019

Hi folks,

I have a tough issue here and need some assistance coming up with a solution. 

Background

Jira Software 8.2.0
Adaptavist ScriptRunner 5.5.8.1-jira8

I have an inherited Jira Software instance that I have been slowly working on cleaning up, as it outgrew its original purpose long ago.

One of my projects has a Single Select List custom field named TTS Approver. It contains a text list users that can approve issues in the TTS project. I'm trying to get rid of this Single Select List in favor of a new Single User Picker custom field, which will be much easier to manage. Let's call it newApprover for now.

Creating the newApprover field is easy enough, and I've added it to the relevant screens in my test environment. The problem I face now is replacing the old TTS Approver information in existing issues (both resolved and unresolved) with this new field. I will then remove the old field from the screens and rename newApprover as TTS Approver. I'm looking at about 35,000 issues in this project alone.

Problem

I thought I could use ScriptRunner's built-in script Copy custom field values to simply copy the value from TTS Approver to newApprover, but this does not work with User Picker custom fields.

Does anyone know a way to script this such that the text value in TTS Approver = the name property of the newApprover user field, and thus the correct user will be populated in the field?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
PD Sheehan
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 Champions.
September 20, 2019

I re-created your json in a map object with only the pertinent information for testing

def resp = [
noOfRecords:2,
apiVersion:"3.0",
persons:[
[core:[firstName:"name1"]],
[core:[firstName:"name2"]]
]
]

Then, I can get this correctly formatted output like this:

def query = "2" //as an example search criteria entered by the user to be bolded in the drop down
def rt = [
items: resp.persons.collect{person->
def html = ""
if (query) {
html= person.core?.firstName.replaceAll(/(?i)$query/) { "<b>${it}</b>" }
}
[value:person.core?.firstName, label:person.core?.firstName, html:html]
}
]

 When I convert rt to a Json, I get the following:

{"items":[
{"value":"name1","label":"name1","html":"name1"},
{"value":"name2","label":"name2","html":"name<b>2</b>"}
]
}
Tomas Arguinzones Yahoo
Contributor
September 21, 2019

Hi @PD Sheehan  that worked...thank you...now that I have your attention :-) I need some assistance with something related to that same API. Now I need to pass that JSON response as the query parameter for another API I need to invoke with the GET method. Using your same JSON response example above,  name1, name2, name3, etc are codes and I need to query another API to get the actual names corresponding to those codes. Something like this:

 

q: "projectId: ("name1" OR "name2" OR ....)

a colleague of mine sent me a similar code in Java but I am not sure how to convert that to groovy so scriptrunner can take it:

q: `projectId:(${assignments.map((assignment) => assignment.projectId).join(" OR ")})`

 

assignment object is coming from the previous API and I need to query another API with that assignment response.

 

Any assistance is greatly appreciated.

 

Thank you very much

PD Sheehan
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 Champions.
September 23, 2019

Can you share some sample code around how you are calling that GET method in the other API?

But if you are just trying to make a string of names with OR as separators:

"${resp.persons.collect{it.core.firstName}.join(' OR ')}"

Tomas Arguinzones Yahoo
Contributor
September 23, 2019

Hi @PD Sheehan  thank you for your reply...I figured it out. And yes, you are in the right track. I did use the join method along some  other string methods to get the 'q' parameter for the next API and I got it working. I do have another issue though, related to this, since the behavior associated to this rest end point works ok in jira but not that really ok in JSD. I will create another question in the Atlassian Community if necessary for that issue but what is happening is:

- when typing in the field in jira, the list of values shows the values matching the 4 characters typed (the way is supposed to work).

- when typing in the field in jira service desk, the list of values shows ALL the values being returned by the rest end point, instead of the values matching the 4 characters typed.

 

Here is the behavior, which is actually a copy of the behavior in the select list conversion documentation in scriptrunner:

 

getFieldByName("Test Text Field").convertToMultiSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner/latest/custom/getProjectNames",
query: true, // keep going back to the sever for each keystroke
minQueryLength: 4,
keyInputPeriod: 500,
formatResponse: "general",
]
])

 

Any idea how to fix that?

 

Thank you

PD Sheehan
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 Champions.
September 23, 2019

Sorry... not much experience yet with scriptrunner and JSD. No I have no idea here.

TAGS
AUG Leaders

Atlassian Community Events