You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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])
}
}
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.