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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Jonny Carter have you tried the above? Is it maybe the fact that it's the ServiceDesk behavior that is behaving differently?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Matthew Page- take a look at https://productsupport.adaptavist.com/browse/SRJIRA-3809 .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey all, you could try the following workaround. Not neat but should do the trick:
def currentURL = "" def headerNames = request.headerNames def headerNamesList = [] while (headerNames.hasMoreElements()){ headerNamesList.add(headerNames.nextElement()) } if (headerNamesList.contains("referer")) { currentURL = request.getHeader("referer") } // the rest of the code here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And how can i get the URL including query string (parameters) in a ScriptRunner UI Fragment?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.