Hi there,
I'm quite new to Scriptrunner und just getting started. I want to use the "Send custom email" workflow postfunction of scriptrunner. Everything is almost fine but there remain two problems:
I'm using this body template:
<ul>
<li><b>Summary:</b> ${issue.summary} </li> <br>
<li><b>Issuekey:</b> ${issue.key}</li> <br>
<li><b>Priority:</b> ${issue.priority} </li> <br>
<li><b>Reporter:</b> ${issue.reporter} </li> <br>
<li><b>Created Date:</b> ${issue.created} </li> <br>
<li><b>Description:</b> ${issue.description} </li> <br>
<li><dl>
<dt><b>All Comments:</b></dt>
<br> XXX
</dl> </li> <br>
<li><b>Text123</b> <br> longer text sentence[...]
</li>
</ul>
1) The ouput of "priority" does not work. Neither in the preview nor in a real testmail. There always occurs:
Priority: IssueConstantImpl[[GenericEntity:Priority][sequence,4]statusColor,#EF612C[name,Very High][iconurl,/images/icons/priorities/major.svg][description,][id,10200]]
What am I doing wrong here? I just cannot figure out what is causing this?!
2) I need to include all comments of the issue (incl. a comment added during the transition of the triggering post function). Previously I've used the jmwe email issue postfunction, but it was limited as I need to change the real From-Sender-Address --> therefore I switched to the scriptrunner postfunction.
In the jmwe postfunction I used this code successfully (provided by the jmwe community leader) to catch all comments:
<%= issue.get("comment").collect{"<dd><li>"+it.bodyHtml+"</li></dd>"}.join('\n') %>
This does not work anymore in the template mentioned above.
How can I achieve in the scriptrunner postfunction to include all comments (at position XXX) of the affected issue in the template?
Thank you all very much for your help in advance.
Best regards
Mario
Hi @Akshay Jain ,
1. How get the values of all the fields in groovy script in script runner.
You can get ALL the issue's fields and their values using the getCustomFieldObjects(issue) and issue.getCustomFieldValue(it) Java APIs.
For example:
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("STORM-1") //replace with an issue key in your instance
// Get all the fields from an issue
def fields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue)
fields.each{
log.warn "$it > " + issue.getCustomFieldValue(it) // Get each field and its value(s)
}You can also refer to the community post here: https://community.atlassian.com/t5/Jira-Software-questions/Get-custom-field-value-of-issue-using-scriptrunner/qaq-p/1389060.
2. How to find out submit has been clicked because on click on that event we want to trigger this script to run.
It seems like you can use a ScriptRunner Listener to listen for a specific event, such as Issue Updated event, to occur in Jira and then carries out an action (execute a script) if the event occurs.
If you like to execute a script during the workflow transitions, then you can consider using the Workflow Post Functions to perform some actions by executing a script after an issue transitions to a new status.
3. How to call POST service from script runner.
You can use the sample script in our Adaptavist library here as a template to make the most common external system calls, such as: post an element to the external system, using its REST API.
I hope this helps.
Thanks for replying @Jia Jie
I am a newbiee in jira and scriptrunner so please bear with my queries.
how can we trigger this groovy script on listner. I am not able to see any field in listener screen to put the groovy script to call the post request.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Akshay Jain ,
No worries!
You can add a new listener by clicking the "Create Listener" button as shown here on the ScriptRunner Listeners page.
Then, in your case, you may create a Custom Listener and put the groovy scripts in the "Inline script" section and select the events to be fired on in the "Events" field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jia Jie thanks for reply what I understood from requirement perspective is I want to trigger this post call on
1. Issue created
2. whenever there is a change in state.
As per your comment custom post functions is more suitable for state change am I understand it correct or listener will be more suitable?
I have created the custom post function but not able to map it with the workflow can you please help on that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Akshay Jain
As you want to trigger the post call on these two conditions: Issue Created and Change of state, I'd suggest using ScriptRunner Listener to listen for a specific event, such as Issue Created and Generic Event, and execute the script when these events occur.
As additional information, you can create a custom event and fire this event from a custom transition post-function in a custom workflow to invoke a listener. The appropriate listener will be alerted of the custom transition by the firing of this event.
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.