How to pass parameter into JQL query string in scriptrunner

oytun_cayli_man_eu March 16, 2021

Hello everyone

I want to set parameter to "assignee" into JQL query string.

I tried but there is no result .

Code below that

----------------------------------------------------------------------------------------------

def slYetkilisiCF = customFieldManager.getCustomFieldObject("customfield_15655")/
def slYetkilisiValue = issue.getCustomFieldValue(slYetkilisiCF)

final jqlSearch = 'assignee = '+slYetkilisiValue
def parseResult = searchService.parseQuery(user, jqlSearch)

Query query = parseResult.getQuery();

------------------------------------------------------------------------------------------

When I executed, get output below;

log.debug(query)->{assignee = c0566(JIRAUSER56893)}

Output is wrong query because (JIRAUSER56893) is extra in string.

It should be assignee = c0566

 

How I pass parameter into JQL query string in script runner?

Thanks for your support.

2 answers

2 accepted

1 vote
Answer accepted
Benz Kek _Adaptavist_
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 Leaders.
March 16, 2021

To add on, what you are passing into the jqlSearch is the ApplicationUser object which gives you: username(userKey)

What you need is just the username which you can get using the method .getName() or .getUsername()

See this API documentation of ApplicationUser for more information. 

Moving forward, you can use something like variable.getClass() or slYetkilisiValue.getClass() to check the object type and read on their respective method in their documentation. For example, a String variable will return "class java.lang.String". 

oytun_cayli_man_eu March 16, 2021

Thanks for your support it is working now.

1 vote
Answer accepted
Hana Kučerová
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 16, 2021

Hi @oytun_cayli_man_eu ,

has your custom field type User Picker (single user)?

If so, please try to do: 

final jqlSearch = 'assignee = '+slYetkilisiValue.getName()

I believe slYetkilisiValue is ApplicationUser object, so you need to get name from it.

oytun_cayli_man_eu March 16, 2021

Thanks for your support it is working now.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events