I created a custom field called 'E-mail Address' . After transititioning an issue to a certain state I want to send an HTTP Post request to a certain url if an email is listed in that issue.
Currently I am checking the empty email condition with:
ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Contact E-mail") != ""
Does anybody have an Idea how I can send the value of the email value to an url: www.exampleurl.com with argument email=issueemail
Thanks!
Here's example of working code -
https://community.atlassian.com/t5/Product-Apps-questions/help-with-REST-using-groovy/qaq-p/17649
To check if field is null or present you can do that with "if" statement in groovy
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def email = customFieldManager.getCustomFieldObjectByName('Email');
// this is the check
if(issue.getCustomFieldValue(email)) {
//code here for REST POST call
} else {
//do nothing
}
Hi Tarun,
I combined the suggestion you posted with a default REST Post groovy example. I am using the following script, but the importing of the classes/dependencies seem to fail.
import com.atlassian.jira.ComponentAccessor;
import groovyx.net.http.HTTPBuilder;
import static groovyx.net.http.ContentType.URLENC;
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def email = customFieldManager.getCustomFieldObjectByName('Email Adress');
// this is the check
if(issue.getCustomFieldValue(email))
{
def http = new HTTPBuilder( 'http://www.example.com/Scripts/test.php' );
def postBody = [username: 'bob']; // will be url-encoded
http.post( path: '/', body: postBody, requestContentType: URLENC )
{
resp -> println "POST Success: ${resp.statusLine}";
assert resp.statusLine.statusCode == 201;
}
}
else
{
//do nothing
}
The debug/output/error console lists the following errors after running the code:
Script2.groovy: 1: unable to resolve class com.atlassian.jira.ComponentAccessor
@ line 1, column 1.
import com.atlassian.jira.ComponentAccessor;
^
Script2.groovy: 2: unable to resolve class groovyx.net.http.HTTPBuilder
@ line 2, column 1.
import groovyx.net.http.HTTPBuilder;
^
Script2.groovy: 3: unable to resolve class groovyx.net.http.ContentType
@ line 3, column 1.
import static groovyx.net.http.ContentType.URLENC;
^
3 errors
Do you have any idea what is going on here?
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.