Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Sending a notification when custom field value changes setup through script runner

naveen arroju November 25, 2021

Hi All,

sending a notification when custom field value changes.
One notification when a custom field is value changed and then get only this action need to get email notification not more of this email.

example: custom field name laptop and values Acer, Dell, Lenovo

when the change to Acer to dell then the dell team will get an email notification. after the ticket is updated assignee or any other issue updated notification is restricted to the dell team.

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 26, 2021

Hello @naveen arroju ,

I think you could use the "Send a custom email" feature from ScriptRunner, using this condition (change the field id with yours) : 

import com.atlassian.jira.component.ComponentAccessor

def nameOfLaptopField = "Laptop"
def idOfLaptopField = 11001
def laptopField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(idOfLaptopField)
def laptopFieldValue = issue.getCustomFieldValue(laptopField)


def laptopFieldChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == nameOfLaptopField}
if (laptopFieldChanged && laptopFieldValue == "Dell"){
//Send mail to DELL team
return true
}
return false

 

Make sure you select each event that may be used to change the field value, i.e. Issue updated for a direct edit, or a transition event - in that case position the event after the issue reindex.

naveen arroju November 27, 2021

Thank you for the update @Antoine Berry 

 

I have modified the code and updated on jira but not work. Can you please check below code

import com.atlassian.jira.component.ComponentAccessor

def nameOfAssigntoqueueField = "Assign To Queue"
def idOfAssigntoqueueField = 10135
def assigntoqueueField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(idOfAssigntoqueueField)
def assigntoqueueFieldValue = issue.getCustomFieldValue(assigntoqueueField)


def assigntoqueueFieldChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == nameOfAssigntoqueueField}
if (assigntoqueueFieldChanged && assigntoqueueFieldValue == "OPS_SLS"){
//Send mail to OPS_SLS team
return true
}
return false

Like Antoine Berry likes this
naveen arroju November 29, 2021

Hi @Antoine Berry,

I have tried the several times above script but not working can you please help on this.

Thank You,

Naveen Arroju.

Like Antoine Berry likes this
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 29, 2021

Hi @naveen arroju ,

please keep in mind that this script is a condition script, meaning that it needs to return "true" for the mail to be sent. You still need to fill the email, subject templates etc.

Also I would need the error message from the logs to be able to help you.

naveen arroju November 29, 2021

Hi @Antoine Berry ,

Thank you for the response.

I have tried again unable to get emails.

please find the below details I have mentioned on sending custom email in script runner 

1 applied to --> selected projected OPSDEV

2. event --->  issue updated 

condition to configuration:- 

import com.atlassian.jira.component.ComponentAccessor

def nameOfAssigntoqueueField = "Assign To Queue"
def idOfAssigntoqueueField = 10094
def assigntoqueueField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(idOfAssigntoqueueField)
def assigntoqueueFieldValue = issue.getCustomFieldValue(assigntoqueueField)


def assigntoqueueFieldChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == nameOfAssigntoqueueField}
if (assigntoqueueFieldChanged && assigntoqueueFieldValue == "OPS_SLS"){
//Send mail to OPS_SLS team
return true
}
return false

3. email template 

Team,

This is a test email for auto-notifications for the SLS queue.
${issue. summary} has been assigned now to the SLS team and requires your attention.

4. subject templet 

Issue ${issue.key} has been assigned to SLS

5. to address 

naveen.sri25@gmail.com

6. saved

please find the attached screenshot and payload 

{ "projects": "[OPSDEV] (java.util.ArrayList)", "@class": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmailCommand (java.lang.String)", "issue": "OPSDEV-1833 (com.atlassian.jira.issue.IssueImpl)", "friendlyEventNames": "Issue Updated (java.lang.String)", "version": "12 (java.lang.Integer)", "relatedProjects": "[[key:OPSDEV, name:(Development Only) NOC Service Desk : xxxxx]] (java.util.ArrayList)", "name": "Send a custom email (java.lang.String)", "canned-script": "com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.SendCustomEmail (java.lang.String)", "id": "75fb2198-d1ea-4bd0-9885-9a042c839fb3 (java.lang.String)", "event": "com.atlassian.jira.event.issue.IssueEvent@1483ea41[issue=OPSDEV-1833,comment=<null>,worklog=<null>,changelog=[GenericEntity:ChangeGroup][issue,26857][author,ug:7716c452-f8a0-45af-abbf-9ae909429e78][created,2021-11-29 16:44:38.103][id,103841],eventTypeId=2,sendMail=true,params={eventsource=action, baseurl=https://xxxxxxxx-dev.com},subtasksUpdated=true,spanningOperation=Optional.empty]", "bundle": "com.atlassian.jira.event.issue.DefaultIssueEventBundle@3c503a7e", "events": "[2] (java.util.ArrayList)" }

Like Antoine Berry likes this
naveen arroju November 29, 2021

custom email send logs.PNG

naveen arroju November 30, 2021

Hi @Antoine Berry ,

Can you please check the above steps and please correct me if I am wrong.

Please reply to me on this issue.

Thank you,

Naveen.

Ivan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 1, 2023
Hello , @naveen arroju 
i did like:
__________________________________________________________________________________________
import com.atlassian.jira.component.ComponentAccessor

 

def nameOfField = "%YOUR_CUSTOM_FIELD_NAME_HERE%"
def FieldChanged = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == nameOfField}
log.info FieldChanged
if (FieldChanged.newstring == "[%YOUR_NEW_VALUE_HERE%]")
    {
    return true
    }
else
    {
    return false
    }
__________________________________________________________________________________________
this works if we know what the new value will be in the custom field
you can read log.info laptopFieldChanged and finde the condition you need.

Thank you,

Ivan.

0 votes
Boris Berenberg - Atlas Authority
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 4, 2021

If you’re open to solving this with an app other than scriptrunner, we natively support this kind of config in Notification Assistant for Jira

Sree Gnanavel Deepak
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 25, 2023

Hey everyone,

Is there any way to find whether the a field is updated or not? And can we get its updation date also?

TAGS
AUG Leaders

Atlassian Community Events