I have made a sample Forge app that listens to the issue created event on Jira Cloud. This is the code of the function that is called whenever the event happens:
export async function onIssueCreated(event, context) {
var myIssue = event.issue;
console.log("issue: " + myIssue);
console.log("Issue key: " + event.issue.key + ".");
var issueKey =myIssue.key;
console.log('Issue created: ' + issueKey + ".");
}
And when an issue is created I get these logs on the Forge tunnel:
INFO 11:40:29.397 ee82e517639665b0 issue: [object Object]
INFO 11:40:29.397 ee82e517639665b0 Issue key: PDM3-5.
ERROR 11:40:29.421 ee82e517639665b0 Cannot read property 'key' of undefined
TypeError: Cannot read property 'key' of undefined
at onIssueCreated (webpack://product-trigger/src/index.jsx:7)
at Reference.value (bootstrap.js:1:10087)
It is absolutely contradictory. I know for a fact that the event parameter contains an issue object and that the issue object contains a key property with the key of the issue.
Also, when printing the myIssue variable, the log shows [object Object] which means that the variable is NOT undefined. Then I event try printing the key of the issue directly from event.issue.key and it works!
But when I try to make the assignment var issueKey =myIssue.key; it says that myIssue is undefined. That’s impossible. Could you help me with this? I have never seen anything like this in my whole software developer career.