Inform the user who made changes in the custom field

 Hello! My first time here and I am new to programming.

I have a code that need to get the user who made a change to a custom field, but I'm having trouble.

The code I'm trying to hit follows, I identified my difficulty with the bold. The objective of this groovy is sending a message to a specific group on Telegram application, but only want the user who made the change in the custom field.

Thanks for any help.


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.UserPropertyManager
import org.apache.commons.httpclient.NameValuePair
import org.apache.http.client.entity.UrlEncodedFormEntity
import org.apache.http.client.methods.HttpPost
import org.apache.http.impl.client.CloseableHttpClient
import org.apache.http.impl.client.HttpClients
import org.apache.http.message.BasicNameValuePair

import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()

CustomFieldManager customFildManager = ComponentAccessor.getCustomFieldManager()

CustomField horasOrcadas = customFildManager.getCustomFieldObjectByName("Horas Orçadas")

String oh = issue.getCustomFieldValue(horasOrcadas);

String assignerName = (issue.getAssigneeUser()!=null ? issue.getAssigneeUser().getDisplayName() : "Sem responsável")

CloseableHttpClient httpclient = HttpClients.createDefault();

HttpPost httpPost = new HttpPost("Info about the group, this part still ok");
httpPost.addHeader("Content-type", "application/x-www-form-urlencoded");
httpPost.addHeader("charset", "UTF-8");
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("chat_id", "the id of the group, ok"));
urlParameters.add(new BasicNameValuePair("text", "Alerta S.O.N.E.\nAlterado: " + issue.getKey() + ".\nUPDATEBY: " + issue.getCreator.getDisplayName() + ".\nResponsável: " + assignerName + ".\nHoras Orçadas: " + oh));
httpPost.setEntity(new UrlEncodedFormEntity(urlParameters, "UTF-8"));

1 answer

1 votes
Timothy Chin Community Champion Oct 19, 2015

that need to get the user who made a change to a custom field, but I'm having trouble.

You'll want to use the ChangeHistoryManager. You can pass a JIRA Issue to the ChangeHistoryManager to get the history for the issue. You'll loop it and find the right customfield and trigger the HttpPost

Thanks Timothy I'll try that!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,870 views 12 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot