Issue with Forge Custom Field Function in Jira App

I’m facing an issue with our Forge app where the function for a read-only custom field is failing. The function is defined in index.js and referenced in manifest.yml, but the app throws a error during execution. I’ve tried cleaning, redeploying, and debugging with forge tunnel, but the issue persists.

index.js

import Resolver from '@forge/resolver';

const resolver = new Resolver();

resolver.define('getAbhi', async (req) => {
  console.log("Function getAbhi was called", req);
  return 'Hello Abhishek';
});

export const handler = resolver.getDefinitions();

manifest.yml

modules:
  jira:customField:
    - key: custom-field-hello-world
      name: custom-field-a
      description: A hello world custom field.
      type: string
      validation:
        expression: value == null || !!value.match("^[A-Za-z]+$")
        errorMessage: The value must consist only of letters
      edit:
        resource: main

    - key: editable-custom-field
      name: editable-custom-field
      description: A editable custom field custom field.
      type: string
      validation:
        expression: value == null || !!value.match("^[A-Za-z]+$")
        errorMessage: The value must consist only of letters

    - key: read-only-custom-field
      name: Read-Only-Custom-Field
      description: A Read Only custom field.
      type: string
      function: getAbhi
      readOnly: true
     

    - key: time-since-created
      name: time-since-created
      description: A time since created custom field.
      type: string
      readOnly: true
      resource:
        function: main

  function:
    - key: main
      handler: index.handler  # Same handler as above

resources:
  - key: main
    path: static/hello-world/build  # Ensure this path is correct

permissions:
  content:
    styles:
      - unsafe-inline

app:
  runtime:
    name: nodejs22.x
  id: ari:cloud:ecosystem::app/3917f6af-5993-4f31-b023-f10e7f6341bd

Note : I want to fetch the hello abhishek from index.js and want to show to read-only-custom-field .

Welcome to the Atlassian Developer Community, @AbhishekJoshi!

At first glance, the code snippet you shared will not successfully deploy due to the function getAbhi you referenced in read-only-custom-field not being defined.

Update: I tried it out and got this error when I called forge deploy

error    jira:customField references undefined function module with key 'getAbhi'

What error are you getting? Using your code snippet as a pattern, it already fails in forge deploy even before I get to install the app.

Cheers,
Ian

Something went wrong

Trace ID: a12da4c8fb194555bc090abdadab9c0c There was an error invoking the function - Cannot read properties of undefined (reading ‘functionKey’)

TypeError: Cannot read properties of undefined (reading ‘functionKey’) at Object.resolve (webpack://jira-custom-field-custom-ui/nod… (truncated)

Refresh app

Hi @AbhishekJoshi,

Based on this requirement, you want to set the read-only custom field (CF) value to 'Hello Abhishek'. To do this, since you are working with a read-only CF, instead of using the function property, you can try value.function.

Here are the changes you need:

In the manifest

    - key: read-only-custom-field
      name: Read-Only-Custom-Field
      description: A Read Only custom field.
      type: string
      # take note that we are using value.function here
      value: 
        function: getAbhi
      readOnly: true

...

  # you need to define the reference to your function 
  function:
    - key: getAbhi
      handler: index.getAbhi   

In your index file

// You need to export it so it can be referenced by the manifest
export const getAbhi = (args) => {
  console.log("Function getAbhi was called", args);
  
  // Assign the value to the returned issue/s
  return args.issues.map(issue => 'hello Abhishek');
}

With these changes to your app and adding the CF to the necessary screens and projects, it should look something like this

.

You can read more about the value function here and how it is used with read-only fields.

Cheers,
Ian

By using the value.function I am able to fetch the ‘Hello Abhishek’. Thankyou sir .

1 Like