Confused about How to Define Readonly Jira Custom Field

jira:customField:
  - key: my-field
    name: My Field
    description: Description of my field
    type: number
    searcher: exact
    readonly: true
  #  view:
  #    resource: ?
  #    isInline: true
  #    experience:
  #      - "issue-view"
  function:
    - key: updateMyField
      handler: resolvers.updateMyField

I’ve created a custom field in my Jira Forge App. I want this to be viewable/exportable in JQL queries. I’m updating the field using the Update Issue REST endpoint:

export const updateIssueCustomField = async (
    issueIdOrKey: string,
    customFieldId: string,
    value: any
): Promise<boolean> => {
    try {
        const response = await api.asApp().requestJira(route`/rest/api/3/issue/${issueIdOrKey}`, {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                fields: {
                    [customFieldId]: value
                }
            }),
        });

        if (response.status === 204 || response.status === 200) {
            console.log(`Successfully updated custom field ${customFieldId} for issue ${issueIdOrKey}`);
            return true;
        }

        const errorText = await response.text();
        console.error(`Failed to update custom field: ${response.status} ${response.statusText} - ${errorText}`);
        return false;

    } catch (error) {
        console.error(`Error updating custom field ${customFieldId} for issue ${issueIdOrKey}:`, error);
        return false;
    }
};

I’m getting an error in my browser console:

Failed to set custom field score: 400 {“errorMessages”:,“errors”:{“customfield_10091”:“Field ‘customfield_10091’ cannot be set. It is not on the appropriate screen, or unknown.”}}

I’m wondering if adding the commented section in the above manifest is needed.

Hi @KeithHamburg,

The error comes from screen settings, make sure the custom field is added to the Edit screen of the project and issue type.

I played around with this and finally got it to work in a company managed project/space but I couldn’t get it working in a team managed space. It does seem odd that even with an app-controlled custom field, it would have to be manually added.

Hello @KeithHamburg

You are confusing GLOBAL fields used by Company Managed projects with LOCALLY scoped fields used by Team Managed projects. The two are not the same.

There currently are no REST API endpoints that allow you to to manage custom fields in a Team Managed project. Refer to JRACLOUD-91386.

Thanks. I added a vote for that issue. So I guess when using the custom field module in the Forge manifest, it creates a global custom field? Can global custom fields be used at all in a team-managed project?

So I guess when using the custom field module in the Forge manifest, it creates a global custom field?

Yep

Can global custom fields be used at all in a team-managed project?

Yes, but the selection and application of that field can only be done in the team managed project’s GUI, as there are no screen schemes that can be managed via the REST API.

Thanks

Ok so one more question. Would using a render function (instead of setting the value at the time of update) allow the value to be displayed in a Team managed project?

Can’t answer that one. Try it and see.