Javascript in custom fields

uday ramakrishna September 8, 2011

I have created some custom javascript in a custom field to display a turnaround time based on the project issue. This works fine but when i update the same it does not take effect. Unsure if this needs some for database clean for this field or restart?

What is not working:

When you update the custom field it does not accept the change we make to the code, the same starts to work soon as a fresh field is created.

4 answers

0 votes
Lior Israeli March 22, 2012

I am trying to copy the content of the Comments field into my own customfield - Comments1

Can you plesae tell me what is the javascript code for doing this?

0 votes
Edwin Chan
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.
September 13, 2011

customfield_10015 is a text custom field and not a date custom field right?

In your original question, you stated that "When you update the custom field it does not accept the change we make to the code, the same starts to work soon as a fresh field is created." What do you mean by it doesn't accept the change? Does it display "The connection is reset" (Firefox)? If this was the problem, then ignore it because this is the standard behavior from JIRA whenever you put javascript into the description.

uday ramakrishna September 15, 2011

Sorry for not being clear. When i change any of the array options or add to them. Save and quit admin section and create a new issue the added items to not get picked. Only when i delete the custom field and create a new one does thie change take effect. Let me know if this is something to do with cache that needs to be flushed?

0 votes
uday ramakrishna September 13, 2011

I read in a post that icould use javascript in the description field that would apply the changes when tested while creating an issue so that works fine. Turnaround time is an arbitrary number that is generated based on some logic of kind of project taking into account the holidays. All these are stored in javascript variables. I am not using any sql or other connections, though i am saving the information back by applying this value to a textfield.

<script type="text/javascript">
function calcDate1(){

prj = document.getElementById("issue-create-project-name").innerHTML;
prj_type = prj = document.getElementById("issue-create-issue-type").innerHTML;

var myDate = new Date();

var endDate = new Date();
var prjVal;

var prjArray = ["4","8","16","11","3","8","6","16","9","4","4","16","9","9"]
var prjNames = ["Options in the dropdown that correspond toprjArray"]


var monthArray = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

for(j=0;j<prjNames.length;j++){
if(prj == prjNames[j])
{
prjVal = prjArray[j];
}
}



var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];


var count = 0;

for(i=0;i<prjVal;i++)
{
endDate.setDate(myDate.getDate()+i);
if(weekday[endDate.getDay()] == weekday[0] || weekday[endDate.getDay()] == weekday[6])
{
count++;
}

}


prjVal = Number(prjVal) + count + 1;

if(prj_type == "Minor Update")
prjVal = prjVal/2;


myDate.setDate(myDate.getDate() + prjVal);


day = myDate.getDate();
month = myDate.getMonth();
year = myDate.getFullYear();


finaldate = monthArray[month] +" / " + day + " / "+year ;

document.getElementById("customfield_10015").value = finaldate; --- textbox that gets populated
document.getElementById("qaFieldHelp").innerHTML = "("+prjVal+ " Businesss days)";
}

</script>

<div id="qaFieldHelp" style="font-weight:bold"> --- A div layer that displays the text of the calculated value

</div>


<script>calcDate1();</script>

0 votes
Edwin Chan
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.
September 12, 2011

Please provide more detail.

1) Are you using the custom field from JIRA Toolkit?

2) How are you displaying the turnaround time? Direct SQL connection? Velocity? Perhaps some sample code might help.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events