I am not able to read defect id in forge custom UI

I have referred to the below link to get the defect id and pass the same to my navigate URL, but it’s not helping. Issue id is not getting fetched.

Below is my code:

index.js -

resolver.define('fooFunction', async (req) => {
  const {projectId, issueKey} = req.context.extensionContext;
  return issueKey
});

App.js -

const redirect = async () => {
    const issueKey = await invoke('fooFunction', {});

    router.open(configData.IQP_Server + "?toolType=JIRA-CLOUD&DomainName=" + configData.Project_Name + "&ProjectName=" + configData.Project_Name + "&applicationName=" + configData.Project_Name + "&defectId=" + issueKey);
  }

Can someone please help me with this? Thanks in advance.

Hi @AnjaliChaudhary,

Based on the Custom UI resolver documentation, try replacing extensionContext with extension. As an example, your req.context looks something like

{
    "accountId": xxx,
    ...
    "extension":
    {
        "issue":
        {
            "key": "TEST-1",
            "id": "10000",
            "type": "Story",
            "typeId": "10001"
        },
        "project":
        {
            "id": "10000",
            "key": "TEST",
            "type": "software"
        },
        "isNewToIssue": false,
        "type": "jira:issuePanel"
    }
}

That said, can you try the following and let us know how it goes?

index.js

resolver.define('getIssue', async (req) => {
  return req.context.extension.issue;
});

App.js

// you can use async/await of course
invoke('getIssue', {}).then((issue) => {
  console.log(`my issue key: ${issue.key}`);
  }
);  

Hope this helps.

Ian

defect id is coming as [Object Object] !!

Hi @AnjaliChaudhary , can you share your code snippet for the invoke? I tried it on my end and I got the issue key and issue ID (issue.id) as expected.

You might also want to check what your req looks like.

Cheers,
Ian

index.js -

resolver.define('getIssue', async (req) => {
  return req.context.extension.issue;
});

App.js -

let issueKey;
    invoke('getIssue', {}).then((issue) => {
      issueKey = issue.key;
      }
    ); 

    router.open(configData.IQP_Server + "?toolType=JIRA-CLOUD&DomainName=" + configData.Project_Name + "&ProjectName=" + configData.Project_Name + "&applicationName=" + configData.Project_Name + "&defectId=" + issueKey);

This is interesting, @AnjaliChaudhary.

With this snippet, I’m thinking more of issueKey being undefined (and not [Object Object]) when it reaches the router.open call.

Can you try the following:

  • Move the router.open call inside then right after issueKey = issue.key; if possible.
  • Log what your req.context looks like (it should be similar to the one I posted above, but just to be on the safe side). From there, you can check why issue.key returns an object.

oh, that was a very silly thing i did. It worked for me now. Thanks a lot for your help.