Shared code JavaScript customfields

Hello,
I would like to check if there is change to share code among several custom fields filled by JavaScript. For example use 1 function in code of 2 calculated custom fields.

I am afraid that answer is not, as they seems to be completely independent containers. But, there’ s always hope :slight_smile:
Thanks
-Petr

Petr,

There IS a possibility to share the code among the custom fields.

You can create a new section in the advanced settings like this:

[jira]
common_javascript_code = '''

// change data type to number
function setNumber(str)
{
  num = Number(str);
  if ( Object.prototype.toString.call(num) === "[object Number]" && !isNaN( num )) {
    return num;
  }
  else {
    return null;
  }
}
'''

Now the function setNumber is available in any of your Javascript custom fields.

Kindly,
Janis, eazyBI support

1 Like

This will save us lot of troubles, thank you.
I am affraid that you accidentally used wrong quotation marks in the end.

I believe the code should be

[jira]
common_javascript_code = '''

// change data type to number
function setNumber(str)
{
  num = Number(str);
  if ( Object.prototype.toString.call(num) === "[object Number]" && !isNaN( num )) {
    return num;
  }
  else {
    return null;
  }
}
'''