Setting number custom field value with value function

I’m trying to use the new value function ability of Forge custom fields.
I’m trying to set a number field, but everytime I do, I get the error

The field value must be a number.

shown in the UI.

Here is my code:

Manifest

modules:
  jira:customField:
    - key: customfield-key
      name: Number Custom Field
      description: This custom field displays a number.
      type: number
      value:
        function: render-number
  function:
    - key: render-number
      handler: index.renderNumber

Functions

const calculateNumber= (field, issueId) => {
  const result = { fields: { [field.id]: 5 };
  return JSON.stringify(result);
};

export const renderNumber= (args) => {
  return args.issues.map((issue) => calculateNumber(args.field, issue.id));
};

I am unsure what exactly the return value of a value function is supposed to be. I tried both: with and without JSON.stringify and neither worked.

1 Like

Hi @MaxGroe, thank you for reaching out and for your feedback regarding documentation.

From the docs: https://developer.atlassian.com/platform/forge/manifest-reference/modules/jira-custom-field/#value-function

The function receives a list of issue IDs and returns a list of values for those issues. The values returned must be compatible with the format expected by the Edit Issue REST API operation. For example, for users the value must be an object that contains accountId.

For a number field it should look like below:

export const renderNumber = (args) => {
  return args.issues.map((issue) => calculateNumber(args.field, issue.id));
};

const calculateNumber = (field, issueId) => {
  return 5;
};

We will improve an example in our documentation. Once again, thank you for the feedback!

2 Likes

Thank you so much! @ljarzabek