Show the contents of field A within field B

OK, so i'm probably overlooking something simple, but here we go:

I've used Jamie's example to prefill a field with static info.
BUT; i would like to use it to show some dynamic info as well.

So instead of:

def desc = getFieldById("customfield_10123")
def defaultValue = """
Hi question-asker,

Thanks for your question.

With kind regards,

Edwin.
 
""".replaceAll(/ /, '')
if (! underlyingIssue?.description) { 
desc.setFormValue(defaultValue) 
}
def desc = getFieldById("customfield_10123")
def name = (getfieldByID("customfield_10102")
def defaultValue = """
Hi $name,

Thanks for your question.

With kind regards,

Edwin.


""".replaceAll(/ /, '')
if (! underlyingIssue?.description) { 
desc.setFormValue(defaultValue) 
}

What am i missing? 
In addition, i would like to add a dynamic part as well.S

So if customfield_10103 == Male,
it should say Hi mr. $name.
In case customfield_10103 == Female,

It should say Hi mrs. $name.

Any pointers?

Thanks in advance guys smile 

1 answer

This widget could not be displayed.

getfieldByID has incorrect casing - you can see that it's different from the first example. Also there is an errant opening bracket.

 

def name = getFieldById("customfield_10102")?.value?.value

should give you the name, and the rest should work.

NB the first getValue() gives you the form value which is an Option object, the second getValue() gives you the string value of the option.

Check your logs too, your example should have produced a compile error.

 

 

Hi Jamie,

Thanks for your reply. I get an error when using the provided example: 

Screen Shot 2016-09-19 at 13.27.31.png

 

I checked the logging as well, and i could retrieve the following:

2016-09-16 23:06:54,076 http-nio-8080-exec-19 ERROR edwin 1386x74525x1 lqq16g 87.214.233.222,0:0:0:0:0:0:0:1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/validators.json [c.o.jira.behaviours.BehaviourManagerImpl] Script function failed on issue: issue: TEST-84, user: edwin, fieldId: __init__, file: <inline script>
groovy.lang.MissingMethodException: No signature of method: Script1.getFieldByID() is applicable for argument types: (java.lang.String) values: [customfield_10102]
Possible solutions: getFieldById(java.lang.String), getFieldByName(java.lang.String)
	at Script1.run(Script1.groovy:6)

So i could have noticed the Id instead of the ID.
 

Hi Jamie,

Any ideas regarding the type checking?

Do you assume that the custom field type is a User Picker and/or Select List? In this case, it's a single text field.

Cheers,

Edwin. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

476 views 3 17
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you