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!