Forums

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

Jira - using scriptrunner web fragments groovy script to insert elements into forms

b April 17, 2020

Hello,

I am new to groovy scripting, but have been dabbling recently. Anyway, I am interested in being able to inject HTML elements in to:

  1. edit issue form
  2. view issue form.

I am not sure exactly how to start diving into this. A lot scriptrunner examples are simple and do not go into any detail. Referencing scriptrunner it looks like web fragment is what I need. Documentation and search results on this subject only yield adding something generic. I am still lost on how to bridge the gap with what I would like to do. I did find something called groovy.xml.MarkupBuilder - here. This makes me think there may be some way to traverse the "sections" DOM but I am lost on how to do this.

Any guidance would be much appreciated (examples, resources ect).

Thanks,

Brandon

2 answers

0 votes
Aron Gombas _Midori_
Community Champion
April 25, 2020

A common technique to inject and execute Javascript in Jira pages is inserting the Javascript fragments to the announcement banner. It is a bit of a hack, but I know it is widely used and it relies on built-in features exclusively (no need for apps).

But, if you want to do this more elegantly, use an app to managed your JS code: https://marketplace.atlassian.com/search?query=jira%20javascript

b May 12, 2020

Thanks for the insight. Im not super excited about using js in the announcement banner. Additionally, our server won't be getting any new plugins, unfortunately. I submitted this question to Adaptive, so ill see what they respond with. I'll feedback if I get anything that answers original question.

0 votes
Aron Gombas _Midori_
Community Champion
April 18, 2020

I may be wrong, but I'd think that ScriptRunner executes the Groovy code fully on the serverside. If so, it is very unlikely that you can access the DOM.

For that, you should inject Javascript fragments to the pages. Those are executed in the browser and allow working with the DOM (at least in Jira Server).

b April 18, 2020

Ah I think your right and maybe Im saying that wrong.. Maybe I mean traversing XML? Basically I am wondering if there is a method other than injecting java script into pages to change elements. With Jira scriptrunner "behaviors" you write groovy scripts to change elements, so I feel it has to be possible.. I just dont know much about this. Trying to learn more and would appreciate any help I can get.

Suggest an answer

Log in or Sign up to answer