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.
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
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:
I instead got the path to the scriptrunner behavior validator :
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
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 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...
Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...
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