I am using a nested ternary to set a value based on another value. Testing the operator in a groovy dev environment works perfectly on it's own. When i implement it in my script, it isn't being evaluated correctly. Am i being tripped up by scriptrunner, groovy truth, Jira or my own stupidity? Please help me solve this mystery!
This is strange to me because the code works fine by itself in an online editor like https://groovyconsole.appspot.com/
********Stand Alone Code in Editor********
def entity = "value 1"
def complianceEmail = (entity == "value 1") ? "email 1" :
(entity == "Value 2") ? "email 1" : "email 3"
print complianceEmail
********END Stand Alone Code in Editor********
However, the statement is not being evaluated correctly in my code. Email 3 is being returned when entity is set to value 1 or value 2. I know I can write this differently since the outcome for value 1 and value 2 should be the same, but this will not always be the case, so i prefer to write it like this for when the outcome for value 2 will change.
Code*************************************************
// all global script vars
groupManager = ComponentAccessor.getGroupManager()
userManager = ComponentAccessor.getUserManager()
issueMgr = ComponentAccessor.getIssueManager()
customFieldManager = ComponentAccessor.getCustomFieldManager()
customerCF = customFieldManager.getCustomFieldObjectByName("Customer Name")
customer = issue.getCustomFieldValue(customerCF)
depositCurrencyCF = customFieldManager.getCustomFieldObjectByName("Deposit Currency")
depositCurrency = issue.getCustomFieldValue(depositCurrencyCF)
disputedAmountCF = customFieldManager.getCustomFieldObjectByName("Disputed Amount")
disputedAmount = issue.getCustomFieldValue(disputedAmountCF)
entityCF = customFieldManager.getCustomFieldObjectByName("Entity")
entity = issue.getCustomFieldValue(entityCF)
resolutionAmountCF = customFieldManager.getCustomFieldObjectByName("Resolution Amount")
resolutionAmount = issue.getCustomFieldValue(resolutionAmountCF)
/**
* sendNotificationToApprovers() Method
* Sends out the Needs Approval notification to the Primary Approver,
* and CCs compliance, Lyn and Olga (CCs are Lyn's request).
* */
def sendNotificationToApprovers() {
def complianceEmail = (entity == "value 1") ? "email 1" :
(entity == "value 2") ? "email 1" : "email 3"
def baseUrl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl")
def reporter = issue.reporter.displayName
def subject = "A Customer Dispute Resolution Requires Your Approval"
def body = "A proposed resolution for a Customer Dispute requires your approval. <br/><br/>" +
"Click the link below to <strong>Approve</strong> or <strong>Reject</strong> the proposed resolution.<br/><br/>" +
"<strong>Dispute Link: </strong><a href=" + "$baseUrl/browse/$issue.key" + ">$issue.key</a> <br/><br/>" +
"<strong>Submitter: </strong>$reporter <br/><br/>" +
"<strong>Customer: </strong>$customer <br/><br/>" +
"<strong>Entity: </strong>$entity <br/><br/>" +
"<strong>Currency: </strong>$depositCurrency <br/><br/>" +
"<strong>Disputed Amount: </strong>$disputedAmount <br/><br/>" +
"<strong>Resolution Amount: </strong>$resolutionAmount <br/><br/>" +
"<strong>Description: </strong>${issue.description} <br/><br/>"
def toAddress = usersToAdd[0].emailAddress
def ccAddress = "$complianceEmail,obessmertnaya@test.com,lyn@test.com "
def bccAddress = "klucio@test.com"
def mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(toAddress, ccAddress, bccAddress)
email.setSubject(subject)
email.setBody(body)
email.setMimeType("text/html")
mailServer.send(email)
} else {
// TODO: Problem getting the mail server from JIRA configuration, log this error
}
log.debug("Entity is $entity")
log.debug("Compliance Address is set to $complianceEmail")
log.debug("Sending notifications - To:$toAddress; CC:$ccAddress BCC:$bccAddress")
}
Logging ******************************
2019-04-24 12:57:00,991 DEBUG [workflow.ScriptWorkflowFunction]: Entity is value 1
2019-04-24 12:57:00,992 DEBUG [workflow.ScriptWorkflowFunction]: Compliance Address is set to email 3
2019-04-24 12:57:00,992 DEBUG [workflow.ScriptWorkflowFunction]: Sending notifications - To:lyn@test.com; CC:email 3,obessmertnaya@ftest.com,lyn@test.com BCC:klucio@test.com