Forums

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

Behaviour script to run JQL query with setConfigParam()

Aimane SBAI
Contributor
March 3, 2021

Hello everybody,

 

I have an issue picker field in my request form and I would like to run a JQL filter using the reporter chosen in the "Raise this request on behalf of" field. 

 

To do that, I did try to use a behaviour script , looks like this :

def issuePicker = getFieldByName("Order")

issuePicker.setConfigParam('currentJql', 'project = "projectA" and issuetype = "Service Request" and status = "In Progress" and reporter = ????????? )

 

What do I have to put instead of ???????? to get the reporter name selected in the "Raise this request on behalf of" field ?

 

Thanks a lot for your help.

2 answers

1 accepted

0 votes
Answer accepted
Aimane SBAI
Contributor
March 4, 2021

@PD Sheehan  Thanks for the answer!

I'm now able to gather the reporter name in the reporterName variable (I did verify that in the logs).

But now, how do I have to put this variable in the JQL query ? (reporter = reporterName does'nt work)

 

def reporterFld = getFIeldById('reporter')
def reporterName = reporterFld.value

def issuePicker = getFieldByName("Order")
issuePicker.setConfigParam('currentJql', 'project = "projectA" and issuetype = "Service Request" and status = "In Progress" and reporter = ?????????')
 

   

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 Leaders.
March 4, 2021

I'd recommend you become familiar with string management methods in groovy. Here is a good place to start: https://groovy-lang.org/syntax.html#all-strings

But basically, there are many ways to define strings:

  • 'single quoted string'
  • "double-quote string"
  • '''triple quoted string'''
  • """triple double-quoted string"""
  • /slashy string/
  • $/dollar slashy string/$

Each has they limitations and advantages. The biggest one is the single-quoted strings can't have variable injections. And when you want to use double-quotes inside the string, I often prefer to switch to slashy string so I don't have to escape the double-quotes.

Here is what your JQL would look like:

issuePicker.setConfigParam('currentJql', /project = "projectA" and issuetype = "Service Request" and status = "In Progress" and reporter = $reporterName/) 
Like David Harkins likes this
Aimane SBAI
Contributor
March 9, 2021

Thank you so much @PD Sheehan !

0 votes
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 Leaders.
March 3, 2021

The "raise issue on behalf of" in the customer portal is really the same as the reporter field in regular jira.

So...

def reporterFld = getFIeldById('reporter')
def reporterName = reporterFld.value

 ... will get you the username of the reporter and you can use that in your jql.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events