Forums

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

Change custom field colour with script runner fragment

Peter June 17, 2020

Can anyone help with this? i want the value of my single select custom field to change to red and bold when i select test risk tier 1 but nothing is happening.. perhaps i am not injecting the code at the right point in the page.. its a single select text custom field that sits where you would expect it to.. see screenshot. any help would be greatly appreciated!

Screenshot 2020-06-17 at 17.19.45.png

 

Condition:

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def risk = customFieldManager.getCustomFieldObject("customfield_13300")
issue.getCustomFieldValue(risk) == "TEST RISK TIER 1"

 

Script:

writer.write("<script>var css = '#customfield_13300-val { color: red; font-weight: bold; border-bottom: 2px solid red; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));</script>")

1 answer

0 votes
Heiko Gerlach
Contributor
June 17, 2020

Hi Peter,

I did something similar but I used scriptrunner behaviours.

The trick to execute javascript is...

def risk = getFieldById("customfield_13300")
risk.setHelpText('<script>Y O U R S C R I P T here</script>').

 

The helptext is sent to the screen and your script will be executed as soon as the screen displays.

 

Cheers

Heiko Gerlach

Accxia

Peter June 29, 2020

Thanks for your help on this, however I am struggling to get it going, here is my script. Apart from the missing conditions on the if statements, can you see anything obvious? Its saying check the setHelpText method exists?

 

Screenshot 2020-06-29 at 15.37.44.png

import com.atlassian.jira.ComponentAccessor

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.fields.CustomField

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.issue.Issue




def CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()

def field1 = customFieldManager.getCustomFieldObject("customfield_13300");

def field2 = customFieldManager.getCustomFieldObject("customfield_13301");




if (field1 == “One”) {

arrivalrisk.setHelpText("var css = '#customfield_13300-val { color: red; font-weight: bold; border-bottom: 2px solid red; }', head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style');head.appendChild(style);style.appendChild(document.createTextNode(css));")

    

} else if (field1 == "Two”) {




    

} else if (field2 == “Three”) {




    

} else if (field3 == “Four”) {




    

}

 

Suggest an answer

Log in or Sign up to answer