Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,301,209
Community Members
 
Community Events
165
Community Groups

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

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

1 vote
Answer accepted
Antoine Berry Community Leader Nov 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.

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

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 Nov 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.

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

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.

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

Suggest an answer

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

📅 Partner Webinar & Events Opportunities: July 2022

Hi community 👋, Here is another monthly roundup of the partner-organized events in July 2022. If there is any event missing please let me know in the comments below 🙏 If you're looking for Atla...

18 views 0 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