Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to Avoid / add Condition to skip empty field value in groovy script

Omprakash Thamsetty
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.
Nov 15, 2023

Hi,

 

I am trying to avoid adding the null value in my email reader. Basically, how I can add validator/condition to skip the field value update if there is no value using groovy script?

 

Ex:

 

My email body content is as below

 

Type:Work Request
Summary: - IN211 - IHCDA - IERA - Visionlink - Question
Severity:
Component:IN211
Division:IHCDA - IERA
ContactName:Brenda Gmail
ContactEmail:brenda.havens@gmail.com
Emailcc:

 

I see Severity field and EmailCC fields were empty. How I can add the condition to skip adding in issueobject. I tried with

 

if (Emailcc[1] != null) condition but this giving me error as there is out of

 

ERROR:

 

Exception thrown while executing the script. java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1

 

Added condition as below.

 

How can I skip or add condition to ignore if there is a null/empty

 

Any help much appreciated.

 

//SET CC address

String EmailccMatcher = "Emailcc:.*"

String EmailccMatcherspace = "Emailcc:\s"

String EmailccMatch = body.find(EmailccMatcher)

String EmailccValue = null

String[] Emailcc = null

log.debug "CC email matcher" + EmailccMatcherspace

if(EmailccMatcherspace){

  log.debug "CC email contain null"

}else if (EmailccMatch) {

    //LastNameValue = LastNameMatch.substring(LastNameMatch.indexOf(':'))

    Emailcc = EmailccMatch.split(":")

if (Emailcc[1] != null) {

  def EmailccField = customFieldManager.getCustomFieldObjectsByName("CC Address Emails").first()

 

  issueObject.setCustomFieldValue(EmailccField, Emailcc[1])

}

}

2 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Nov 16, 2023

Hi @Omprakash Thamsetty

Could you please provide more information, i.e., what are you using to validate this? Is it a Post-Function or a Validator?

If it is a Post-Function, what Post-Function feature are you using? Else if it is a Validator, what type of validator are you using?

It would be helpful if you could also share a screenshot of your configuration.

I'm looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

0 votes
Robert Bailey
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.
Nov 16, 2023 • edited

Hi @Omprakash Thamsetty , 

 

When you use the .split function, it will only fill out the array with the data available. So, if you only have "Emailcc:" your array will only have 1 entry, so trying to access the second value will fail. 

Instead, you can check the length of your array, so instead use this if: 

if(Emailcc.length > 0){

}


This confirms if there is anything after ':'. 

Does this help?

Kind regards, 

Bobby

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.15
TAGS
AUG Leaders

Atlassian Community Events