How to reference a Custom Field Value in a Confluence Page

Hi guys,

Im trying to post a custom field value in a Confluence Page when a JIRA issue is created (post function). I tried to do to as follows but it didnt work for me.

 

def cField1 = customFieldManager.getCustomFieldObject("customfield_10008")
def cField2 = customFieldManager.getCustomFieldObject("customfield_10009")
def cField3 = customFieldManager.getCustomFieldObject("customfield_10201")

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro' ('ac:name': "jira") {
'ac:parameter' ('ac:name': "key", issue.key)
}

// add more paragraphs etc

xml.p ("${issue.getCustomFieldValue(cField1)}")
xml.p ("${issue.getCustomFieldValue(cField2)}")
xml.p ("${issue.getCustomFieldValue(cField3)}")

 

I've imported:

import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import groovy.xml.MarkupBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager

 

And the error i recieve is:

2017-09-14 17:18:19,174 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-09-14 17:18:19,174 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SMP-19, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: customFieldManager for class: examples.docs.Script226
	at examples.docs.Script226.run(Script226.groovy:50)

 

Im really stuck here, can someone help me? thanks in advance.

1 answer

1 accepted

hey Alejandro, 

You will need, after the imports, something like 

def customFieldManager  = ComponentAccessor.customFieldManager

Thank you Thanos, It worked perfectly

Hi Thanos,

 

I resolved the problem with your suggestion but now i want to "italic" the text, and I dont know how to do it, I tried to search something similar in the web but with no luck.

 

Can you help me with this? (I tried this code below)

xml.p ("<em>${issue.getCustomFieldValue(cField1)}"</em>")
xml.p ("<em>${issue.getCustomFieldValue(cField2)}</em>")
xml.p ("<em>${issue.getCustomFieldValue(cField3)}</em>")

Suggest an answer

Log in or Join to answer

Stay in touch

Be the first to know what's trending on Atlassian Community

Community showcase
Gregory Van Den Ham
Published Monday in Jira

Got TLSv1.2?

...connector settings, you'll see something like: <Connector SSLEnabled="true" if you don't see a line that says "ciphers=".....", you may have a problem. How to fix it? So you got a B on your...

101 views 2 1
Read article
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot