How to display a default text in a Custom Field through javascript whenscreen or form loads.

Aditya Verma
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 5, 2015

Hi JIRA Team,

I am trying to load a default value in a Custom Field(Textbox) by adding javascript code in description of that particular field. But the text does not appear in textbox. Could you please let me know how to do it. I tried below codes.

  1. <script type="text/javascript"> document.getElementById("customfield_13003").value = "HelloWorld"; </script>
  2. AJS.$(document).ready(function(){ AJS.$("#customfield_13003").val = "HelloWorld"; } );

Thanks in advance. 

1 answer

0 votes
João Palharini
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 9, 2015

Hey Aditya!

In order to run code on custom fields we normally use Script Runner. It's a very simple yet very popular plugin for JIRA those days and it can do lots of powerful things. Documentation for it can be found here and the plugin can be downloaded from Atlassian Marketplace here.

In order to display a simple text when loading the page, what you can do is install the Script Runner add-on, create a Custom Field setting its type to Script Field and, on the Add-ons tab of JIRA's Administration page, you can set the script you want to run on that field. 

information By the way, the Script Runner add-on uses Groovy as its programming language, so it's very easy to write code for it as it's very similar to Java.

There are lots of documents that can help you achieve great things over at the Script Runner documentation and I also tagged your question with the add-on's label, so that the developer may show up here and help you with that as he has much more knowledge of programming on there than us! wink

Cheers!

-Joao

Suggest an answer

Log in or Sign up to answer