Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner custom listener script on work logged on issue event.

Hi Team ,

I am trying place to script in script runner listeners (work logged on issue event) . Please find error screenshot attached.

script is for to send email to some list of users when the time logged (calculated number custom field A ) is greater than 80% of custom field B number field in issue.
below script is working In Jira groovy console when execute against particular issue.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.mail.Email;
import com.atlassian.mail.queue.SingleMailQueueItem;

import com.atlassian.jira.issue.worklog.Worklog
import com.atlassian.jira.issue.worklog.WorklogManager
import com.atlassian.jira.issue.MutableIssue

import org.apache.log4j.Logger
import org.apache.log4j.Level

import com.onresolve.scriptrunner.runner.util.UserMessageUtil

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

WorklogManager worklogManager = ComponentAccessor.getWorklogManager()

Double total = 0;
Double total1 = 0;

def customField_orgEE = customFieldManager.getCustomFieldObjectsByName( "Original EE" );
def customField_aclrtd = customFieldManager.getCustomFieldObjectsByName( "Actual Reported" );

def issue = event.issue as MutableIssue



//Taking orginal EE field value and calucalte 80% from
Double sp = issue.getCustomFieldValue( customField_orgEE );
total += sp;
originalEE = 0.8 * total

//taking Actual Reported field value from RMID
Double sp1 = issue.getCustomFieldValue( customField_aclrtd );
total1 += sp1;
if (total1 >= originalEE) {
def email = new Email(issue.get("customfield_12912")?.emailAddress)
email.setSubject("Jira time logged threshold")
email.setBody("Hello, Total time spent on RMID is reached more than 80% of OriginalEE for ${issue.getKey().toString()}. Kindly check it")
SingleMailQueueItem item = new SingleMailQueueItem(email);
ComponentAccessor.getMailQueue().addItem(item); "*** RMID email sent"



1 answer

Hi @Gunti_Reddy 

I can't see the screenshot about the error. Have you forgotten to attach it? 

Hi @Tuncay Senturk _Snapbytes_ 

Thanks for valuable response , i made below changes

It seems like the getCustomFieldObjectsByName is not able to capture the custom field object.

def customField_orgEE = customFieldManager.getCustomFieldObjectsByName( "Original EE" );
def customField_aclrtd = customFieldManager.getCustomFieldObjectsByName( "Actual Reported" );

replaced getCustomFieldObject api for example:

def customField_orgEE = customFieldManager.getCustomFieldObject("custom_10000");
def customField_aclrtd = customFieldManager.getCustomFieldObject("custom_10001");

Till here script works fine, my requirement is slightly changed now. 

whenever user worklog done on story. i need to get custom field value (it holds parent issuekey )from that story . 

and get custom field values from parent issue and compare and send email.



I did some thing like, no issues now.

//taking custom field vaue from storydef rmidkey = customFieldManager.getCustomFieldObject("customfield_12909")
def cfValue = issue.getCustomFieldValue(rmidkey)
def rmidCf = ComponentAccessor.getIssueManager().getIssueByCurrentKey("${cfValue}");
def customFieldOrgEE = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10000');
def customField_aclrtd = ComponentAccessor.getCustomFieldManager().getCustomFieldObject('customfield_10001');

//taking custom field value from parent issue

rmidcfValue = rmidCf.getCustomFieldValue(customFieldOrgEE) as Double;




Hi @Gunti_Reddy 

Sorry for the late response.  getCustomFieldObjectsByName returns a list of custom fields of which name is the parameter you provided. It is always the best way to fetch custom field by ID, as you did later.

Anyway, as far as I understand you're storing the parent issue key in a custom field.

You can get parent issue of any issue by calling issue.getParentObject() method.


Like Gunti_Reddy likes this

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

221 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you