Forums

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

Set Text Field Formatting Post-Function

Patrice Marrec (Valiantys) March 23, 2018

Hi,

I'm trying to set a Text field to bold in a view screen.
Started with JS in Announcement Banner, it works but breaks UI in many places. 

Here is the code: 

<script type="text/javascript">
(function($){ jQuery(document).ready(function($){
document.getElementById("customfield_10700-val").style.fontWeight = "900";
document.getElementById("customfield_10700-val").style.fontWeight = "bold";
document.getElementById("customfield_10700-val").style.textTransform="uppercase"
$(function(){
});

}); })(jQuery);
(AJS.$);
</script>

I am now trying to find a new way to do this, in a post-function where I get the custom field text value: 

def txtfield = customFieldManager.getCustomFieldObject("customfield_10700")
def txtfieldval = issue.getCustomFieldValue(txtfield)

Is there a way to manipulate formatting with Atlassian SDK/API? 

I would need to set that Text Field renderer to 'Wiki Style Formatting' in Field Configuration, I'm just trying to find ways to manipulate those variables (Font size, font weight etc) 

Many thanks 
 

1 answer

1 accepted

1 vote
Answer accepted
Patrice Marrec (Valiantys) March 23, 2018

Solved it, if anyone needs it: 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.event.api.EventPublisher
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.renderer.wiki.AtlassianWikiRenderer
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory

// Get Custom Field Value
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def targetField = customFieldManager.getCustomFieldObject('customfield_10700')
def changeHolder = new DefaultIssueChangeHolder()

def rendererManager = com.atlassian.jira.component.ComponentAccessor.getComponent( com.atlassian.jira.issue.RendererManager.class)
def fieldLayoutItem = com.atlassian.jira.component.ComponentAccessor.getFieldLayoutManager().getFieldLayout(issue).getFieldLayoutItem("customfield_10700")
def renderer = rendererManager.getRendererForField(fieldLayoutItem)
String desc = renderer.renderAsText(issue.summary, null)

desc = ('h2.' + '*' + desc + '*')

targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), desc),changeHolder)


It copies value from summary into a text field, sets it as h2 and strong. 

Suggest an answer

Log in or Sign up to answer