Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

scriptrunner: Behaviour/Initialiser Function issues with .getValue()

b April 7, 2020

Hello,

I am new to jira scriptrunner/groovy... I am trying to use "Behaviour/Initialiser Function" from script runner to load dynamic descriptions to edit issues screen based on some custom field values. All but one field is located on the edit issue form. One is located on the view issue form. Currently my problem appears to be that I can't seem to grab ANY field values which is very frustrating.. I have been trying a lot of different variations in syntax to to accomplish this goal.. None have been successful. Below is my current script.

/****************BEHAVIOR-INITILISER FUNCTION SCRIPT****************/

//View issue screen (#issue-content) single value text fields
def FV1 = getFieldById("customfield_10175").getValue()

//Edit issue screen (#edit-issue-dialog) single value drop-down fields
def FV2 = getFieldById("customfield_10128").getValue()
def FV3 = getFieldById("customfield_10162").getValue()
def FV4 = getFieldById("customfield_10169").getValue()
def FV5 = getFieldById("customfield_10151").getValue()
def FE1 = getFieldById("customfield_10156")
def FE2 = getFieldById("customfield_10131")
def FE3 = getFieldById("customfield_10127")
def FE5 = getFieldById("customfield_10185")
def FE6 = getFieldById("customfield_10154")

//Edit issue screen (#edit-issue-dialog) input text field
def FE4 = getFieldById("customfield_10153")

if (FV1 != null && FV2 == "RTN" || FV2 == "NG" || FV3 == "RTN" || FV3 == "NG" || FV4 == "RTN" || FV4 == "NG" || FV5 == "RTN" || FV5 == "NG") {
FE1.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

} else if (FV1 != null && FV5 == "OK") {
FE1.setDescription('test')
FE2.setDescription('test')
FE3.setDescription('test')
FE4.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

} else if (FV1 == null) {
FE1.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

}

Please help me understand what Im doing wrong... Im beating my head on a wall at this point.

1 answer

0 votes
b April 8, 2020

This might be intuitive to someone that is familiar with groovy but not for me... I had to piece this together from a lot of different places to get this to work. Hopefully this helps somebody else.

/****************BEHAVIOR-INITILISER FUNCTION SCRIPT****************/

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
Issue issue = underlyingIssue
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()

//View issue screen (#issue-content) single value text fields
def FV1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10175"))

//Edit issue screen (#edit-issue-dialog) single value drop-down fields
def FV2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10128")).toString()
def FV3 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10162")).toString()
def FV4 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10169")).toString()
def FV5 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10151")).toString()
def FE1 = getFieldById("customfield_10156")
def FE2 = getFieldById("customfield_10131")
def FE3 = getFieldById("customfield_10127")
def FE5 = getFieldById("customfield_10185")
def FE6 = getFieldById("customfield_10154")

//Edit issue screen (#edit-issue-dialog) input text field
def FE4 = getFieldById("customfield_10153")

if (FV1 != null && FV2 == "RTN" || FV2 == "NG" || FV3 == "RTN" || FV3 == "NG" || FV4 == "RTN" || FV4 == "NG" || FV5 == "RTN" || FV5 == "NG") {
FE1.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

} else if (FV1 != null && FV5 == "OK") {
FE1.setDescription('test')
FE2.setDescription('test')
FE3.setDescription('test')
FE4.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

} else if (FV1 == null) {
FE1.setDescription('test')
FE5.setDescription('test')
FE6.setDescription('test')

Suggest an answer

Log in or Sign up to answer