Getting and setting a field in Forge

Hi folks, I’m very much a newbie so I hope you’ll forgive a basic question.

I’ve completed the Forge Introduction tutorial (it was very good) and got everything working. But there is a bit of a gap between those and the suggested “next steps” pages.

At the moment, I just want to enhance the app I created in the tutorial to display the value of a field in the issue, and then let me update that field. Quite a simple idea, but I’m struggling to figure that out. I’m looking at the sample apps, some of which are quite sophisticated, but so far I haven’t cracked it.

Your assistance would be appreciated, whether with a code sample or pointing me in the right direction. Thanks!

Update

I managed to read the field by hacking the code in the tutorial and some trial and error. I created this little function in the index.js:

const fetchStatusForIssue = async (issueId) => {
  const res = await api  
    .asUser()
    .requestJira(route`/rest/api/3/issue/${issueId}?fields=status`);
 
  const data = await res.json();
  return data;
};

And I called it like this:

 const [status] = useState(async () => await fetchStatusForIssue(context.platformContext.issueKey));
 console.log(`Status of this issue: ${status.fields.status.name}`);

My question now is whether there is a more elegant way to do this?

Hi @craig.schwarze,
I believe you were following the tutorial in here . You can get the data from issue fields by calling rest api and configuring correct scopes as mentioned in the above tutorial. JIRA rest api details are available in https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/. For Confluence it is https://developer.atlassian.com/cloud/confluence/rest/intro/.

This should be the API calls you will have to use as if I understood your requirement correctly.

You can find more sample apps in here as well.

Thanks Lashani,

I tried to modify the example from the tutorial. For example, I tried to get the issue status with this function:

const fetchStatusForIssue = async (issueId) => {
  const res = await api
    .asUser()
    .requestJira(route`/rest/api/3/issue/${issueId}/status`);

  const data = await res.json();
  return data;
};

What it is returning is:


[object Object],(payload) => {
            reconcilerState_1.default.enqueueSideEffectIfEnabled({
                type: 'action',
                hookIndex: currentHookIndex,
                componentKey,
                payload
            });
        }

Hi @craig.schwarze ,
Please try with the below sample

.requestJira(route/rest/api/3/issue/${issueId}?fields=status)

status is nested under issue fields.

1 Like