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

JIRA Scriptrunner access URL

Hi 

I was wondering if it's possible to get the full URL for the JIRA create issue page from inside Scriptrunner. At the moment I'm able to get the jira.base url from the ApplicationProperties using the ComponentAccessor.

Ideally, I'd like to get the full url, including any arguments contained within the URL. Does another application property or any other component accessor expose this information?

What I'm trying to do is populate some values in a JIRA issue on the create screen using the behaviours part of Scriptrunner. The user will be taken to JIRA with a parameterised URL which fills out some of the fields such as summary, passed in as args.

However, the URL also contains an id field as an argument which I'm hoping Scriptrunner can extract from the URL and then use to poll an API to populate other fields on the create issue page.

Cheers

Paul

1 answer

Since you're working with Behaviours, there's a variable in the binding for the current request. It's an HttpServletRequest object. Inside your Behaviour's Groovy script, you could get the URL as a string using

request.requestURL.toString()

You could then parse that URL string and retrieve its query parameters using normal Java methods. See the answers at https://stackoverflow.com/a/13592324/1524502 for some examples.

You may also want to take a look at the Create Constrained Issue functionality in ScriptRunner.

When I tried this I didn't get the URL of the browser like I was after:

https://mySite.site.com/servicedesk/customer/portal/1/create/69?summary=bbb

I instead got the path to the scriptrunner behavior validator :

https://mySite.site.com/rest/scriptrunner/behaviours/latest/jsd/jsd/validatorsByPid.json

any way to get the former?

@JamieA : this might solve some big issues a number of us are having..this could be a simple way to get a clickable URL to land me on a serviceDesk request form with some of the fields pre-filled.   In truth, what I want is the first page on a service desk portal entry box a person to type in their issue, it does the search, you dont see a match in the KB articles so you click a request type and DANG, I have to type that sentence in again as the summary.  BUT! if you see the URL on the request form it's got those words...embedded as a query param like "q=my+issue+is+about+this..." so ScriptRunner behaviour may conceivably pull it out and stick it in the summary line?   This can also enable a host of other applications to redirect troubles to some requestTypes with a number of pre-fills

Hi @Jonny_Carter have you tried the above?  Is it maybe the fact that it's the ServiceDesk behavior that is behaving differently? 

Hey, @Matthew Page -

So, my bad on suggesting you use the request URL. I ought to have realized that the request would be to the Behaviours endpoint, _not_ the create issue page. My bad!

While I do suspect you could construct the service desk URL within the Behaviour, I am beginning to think that maybe Behaviours aren't the right thing for your particular use case. While Behaviours can pull things from form fields, they can't get the URL from the current context.

The only way I can think to get the URL using ScriptRunner at present would be via some custom JavaScript using a Web Resource.

The code below, for example, would get the query string:

const url = new URL(window.location.toString());
const params = new URLSearchParams(url.search);
const query = params.get('q');

Of course, writing the JS to then update the summary field and so forth would take further doing. Also, your mileage may vary on using the above URLSearchParams API.

I'm mulling over whether there isn't a feature request here. Let me get back to you...

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Confluence

What project did you transition or start on Confluence with the shift to remote work?

It’s been great to hear from fellow users over the last few weeks about the best tips and fun moments you’ve had working on Confluence since the transition to working remote. I’d love to keep the c...

160 views 3 8
Join discussion

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