Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,366,179
Community Members
 
Community Events
168
Community Groups

How to identify groovy script in scriptrunner that submit button is clicked & call POST service ?

I have written a post script which I want to call and get all the fields value in the Jira incident and send that post request.

Questions:

 1. How get the values of all the fields in groovy script in script runner.

 2. How to find out submit has been clicked because on click on that event we want to trigger this script to run.

3. How to call POST service from script runner.

1 answer

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.

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. 

@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.

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. 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events