Unable to update a Custom Field that my own Forge app created

I have an on-install trigger in my Forge app and it creates a custom field on the Issue to carry an external ID. The field is created OK - I can even see it in the Advanced Search list. But any attempt to update it from another part of my Forge app, where I create a new issue and update this custom field, gives me this error: “This API works only with fields provided by Forge apps.” Here’s the code.
The on-install trigger:

  var body_data = '{ "name": "My External ID", "description": "Custom field for integrating my External App", "type": "com.atlassian.jira.plugin.system.customfieldtypes:textfield" }';
  //  add the custom field
  try {
    response = await api.asApp().requestJira(route`/rest/api/3/field`, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: body_data
    });  
  } catch (err) {
    return ({ detail: err, stage: "on-install-event", status: "error" });
  }
  var t1 = await response.json();

The API call where I first create the issue, then try to update it is below. The issue is created OK, but the subsequent Update fails.

    var b1 = { update: {}, fields: {
        summary: api_body.summary,
        description: {
          type: "doc",
          version: 1,
          content: [
            {
              type: "paragraph",
              content: [
                {
                  type: "text",
                  text: api_body.description
                }
              ]
            }
          ]
        },
        project: {
          id: api_body.project_id
        },
        issuetype: {
          id: api_body.issue_type_id
        }
      }
    };
    var body_data = JSON.stringify(b1);
    //  console.log("Packet for adding Issue: " + body_data);
    //  insert the issue
    try {
      response = await api.asApp().requestJira(route`/rest/api/3/issue`, {
        method: 'POST',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: body_data
      });  
    } catch (err) {
      console.log("Error adding Issue: " + err + "; Data: " + body_data);
      return ({ detail: err, stage: "add-issue", status: "error" });
    }
    var t1 = await response.json();
    console.log("Added Issue: " + JSON.stringify(t1));

    console.log("Mapping field to update: " + JSON.stringify(api_body));
    var bodyData = '{ "updates": [ { "issueIds": [ ' + t1.id + ' ], "value": "' + api_body.column_value + '", "customField": "' + api_body.column_name + '" } ] }';
    console.log("Will update field: " + bodyData);
    const r1d1 = await api.asApp().requestJira(route`/rest/api/2/app/field/value`, {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: bodyData
    });  
    var t2 = await r1d1.json();
    console.log("Response from updating field: " + JSON.stringify(t2));

The final console log says this: Response from updating field: {“errorMessages”:[“This API works only with fields provided by Forge apps.”],“errors”:{}}

The field reference itself is OK. Here’s what the “Will update…” log says, for example: Will update field: { “updates”: [ { “issueIds”: [ 10025 ], “value”: “12345678-0000JnSjeAAF”, “customField”: “customfield_10037” } ] }. I have confirmed within my Jira instance that my newly-created Custom Field is indeed called customfield_10037.

What am I doing wrong?

One other thing I notice: I don’t see my Custom Field in any of the views, when I look at an issue. I can only see it in the Advanced Search list view. Why would that be?

Thanks in advance for you help!

Hey, @KishoreMandyam,

That API works only for custom fields and custom field types defined in the Forge app manifest. It seems that in your app you created a field of a built-in type com.atlassian.jira.plugin.system.customfieldtypes:textfield. It is a regular custom field that can only be updated by regular means (with the edit issue API).

Thanks, @kkercz, I’ll look at this in more detail.

I used the Update only because, if I use the Custom Field in my Add API call, that fails with “Field ‘customfield_10037’ cannot be set. It is not on the appropriate screen, or unknown.” Why would that be? Is there no way I can use a Custom Field in the Add API?

Related: Why am I not able to see the Custom Field in any view, even though I have associated all my Screens with it?

BTW, just so I don’t bother people here with these very basic issues: Is there like a Guidebook or something that tells me what to do in the most common use-cases? Like creating my own custom-field and so on? Where should I have gone in the doc to know that I should first define my field in the manifest and then update it, instead of just using an API directly?

Pardon me for all the questions. Thank you for all your help!

Why am I not able to see the Custom Field in any view, even though I have associated all my Screens with it?

That’s unexpected. Usually adding fields to screens in your project should be enough. You could try to use the find your field functionality to find out what’s going on.

I’m afraid there is no comprehensive guide on how to extend Jira with custom fields. Definitely something we could improve!