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.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.link.IssueLinkManager;
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.setCc("xxxxx.com")
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);
log.info "*** RMID email sent"
}
Thanks,
Gunti
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.
Thanks,
Gunti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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;
Thanks,
Gunti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
Best
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.