I need to turn off JIRA notification scheme and use my own Custom Email for sending updates on Issues - I am sending an email to Reporter when Issue is resolved and need to include Survey link in the Resolution email - I was trying to use below:
https://serverurl/servicedesk/customer/portal/3/IT-XXX/feedback?
But this doesn't seem to work - do we need token that is sent in JIRA resolution email.
I know I need to use Script in JIRA Post function to set a Custom field using JIRA Rest API for token - /rest/api/2/issue/{issueIdOrKey}/properties/feedback.token.key
Does anyone has Sample script to Call Rest API and set Custom field with response value. Please help.
I am using a script post function to set Feedback token property using Rest call in script itself - here is the code:
#################################################################
import groovy.json.JsonSlurper;
import com.atlassian.jira.issue.CustomFieldManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.issue.fields.CustomField
import org.apache.commons.lang.RandomStringUtils
import com.atlassian.jira.config.properties.APKeys
IssueService issueService = ComponentAccessor.getComponent(IssueService);
MutableIssue mutIssue = (MutableIssue)issue
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def groupManager = ComponentAccessor.getGroupManager();
def customFieldManager = ComponentAccessor.customFieldManager
IssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder()
IssueIndexManager issueIndexManager = ComponentAccessor.getComponent(IssueIndexManager.class)
IssueIndexingService issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
def issueManager = ComponentAccessor.getIssueManager()
def issuekey = mutIssue.key
String base_Url = ComponentAccessor.getApplicationProperties().getDefaultBackedString(APKeys.JIRA_BASEURL)
def itSurvey = base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"
System.out.println("itSurvey :::: "+ itSurvey)
InputStream response = get(itSurvey)
def baseURL = base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"
private InputStream get(String baseURL) {
String charset = (('a'..'z') + ('0'..'9')).join()
Integer length = 30
String randomString = RandomStringUtils.random(length, charset.toCharArray())
def issueManager = ComponentAccessor.getIssueManager()
MutableIssue mutIssue = (MutableIssue)issue
def issuekey = mutIssue.key
def issueID = mutIssue.getId()
def data ="{\"token\":\""+randomString+"\",\"issueID\":"+issueID+"}"
def url = new URL(baseURL);
System.out.println ("+++++++Issue Key ::::: "+issuekey)
System.out.println ("+++++++Issue ID ::::: "+issueID)
System.out.println ("+++++++Token ::::: "+randomString)
HttpURLConnection connection = url.openConnection() as HttpURLConnection;
connection.requestMethod = "PUT"
connection.setRequestProperty("Authorization", "Basic amlyYXNkX2ludGVncmF0aW9uOmppcmFzZGludGVndHN0")
connection.setRequestProperty("OSLC-Core-Version", "2.0")
connection.setRequestProperty("Accept", "application/json")
connection.doOutput = true
connection.connect()
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes (data);
wr.flush ();
wr.close ();
println "responseCode: " + connection.getResponseCode()
InputStream response
if (connection.getResponseCode() == 200){
response = connection.getInputStream()
}
return response
System.out.println("Response::::" + response)
}
def curl = "curl -u user:pwd -X GET -H \"Content-Type: application/json\" "+base_Url+"/rest/api/2/issue/"+issuekey+"/properties/feedback.token.key"
System.out.println("CURL:::: "+ curl)
def output = curl.execute().text
String contentM = new java.util.Scanner(output).useDelimiter("\\A").next();
def jsonSlurperM = new JsonSlurper()
def objectM = jsonSlurperM.parseText(contentM)
def token = objectM['value']['token']
System.out.println ("Token ::::::"+token)
Collection cf_Survey = customFieldManager.getCustomFieldObjectsByName("Survey Token")
def iterator1 = cf_Survey.iterator()
CustomField customField_Survey
while(iterator1.hasNext()){
customField_Survey = iterator1.next()
}
ModifiedValue modifiedValue = new ModifiedValue(mutIssue.getCustomFieldValue(customField_Survey), token)
mutIssue.setCustomFieldValue(customField_Survey, token)
customField_Survey.updateValue(null, mutIssue, modifiedValue, issueChangeHolder)
issueIndexingService.reIndex(mutIssue)
############################################################
Then using this custom field in email sent to customer. You can try and let me know if this helps...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Perhaps the following solution can help you:
I solved that by 1st checking if the ticket already has a token generated because I realized sometimes that token in not created right after the ticket was moved to Resolved/Closed (or Resolution = Done)
https://company.atlassian.net/rest/api/2/issue/{{issue.key}}/properties/feedback.token.key
After that, I check if the web response is empty. If so, it means you need to generate the token in order to compose the link that will be sent to the user and allow him/her to respond to CSAT
Finally, I add another Web Request to generate the token. Here there is a risk: I'm not generating random tokens (probably more secure to avoid smart people acting like a user and responding to the survey - anyway, in my scenario this is not a concern)
I run again a Web Request to get the token that has just been generated
Then I send the email:
Best Regards,
Anderson.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
It is important to remember about token, because your website might not have public access.
How to create token and how to use it. (You can still use get method instead of POST)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jyoti,
I am facing a similar issue. Have you found a solution to your problem? Thank you.
Best regards,
Alban
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.