Cloud Behaviour Set field read-only in a given issue status

Hi All, this might be a repost, but it took me a while to figure out.

Overview
Set a Jira filed to be read only when the issue is in a given status

This example will work on the Create View in Jira Cloud only.

/-----------------------------------------------/
/* Obtain status for trigger issue /
/
-----------------------------------------------*/
const context = await getContext();
const myKey = context.extension.issue.key;
const myissue = await makeRequest(/rest/api/2/issue/${myKey});
const statusName = myissue.body.fields.status.name;

if (statusName == “In Progress”) {
//Summary to be read only
getFieldById(“summary”).setReadOnly(true);
}


CoPilot explanation of the code:

Copilot

Sure, I’d be happy to explain this code as well. It’s also written in JavaScript and interacts with the Jira Cloud REST API to obtain the status of a specific issue.

Here’s a breakdown of what each line does:

  1. const context = await getContext(); - This line calls the getContext function, which is assumed to return the current context. The context typically contains information about the current state of the application or script.
  2. const myKey = context.extension.issue.key; - This line extracts the key property from the issue object within the extension object of the context. In Jira, the key is a unique identifier for an issue.
  3. const myissue = await makeRequest(/rest/api/2/issue/𝑚𝑦𝐾𝑒𝑦‘);‘−𝑇ℎ𝑖𝑠𝑙𝑖𝑛𝑒𝑚𝑎𝑘𝑒𝑠𝑎𝑟𝑒𝑞𝑢𝑒𝑠𝑡𝑡𝑜𝑡ℎ𝑒‘/𝑟𝑒𝑠𝑡/𝑎𝑝𝑖/2/𝑖𝑠𝑠𝑢𝑒/myKey‘);‘−Thislinemakesarequesttothe‘/rest/api/2/issue/{myKey}endpoint of the Jira Cloud REST API, where${myKey}` is the key of the issue we’re interested in. This endpoint returns detailed information about the specified issue.
  4. const statusName = myissue.body.fields.status.name; - This line extracts the name property from the status object within the fields object of the response body of the previous request. This name is the name of the current status of the issue.

So, in summary, this script is used to fetch the current status of a specific issue in Jira. The issue is identified by its key, which is obtained from the current context. The name of the status is then stored in the statusName variable. Please note that this code needs to be run in an environment where the getContext and makeRequest functions are defined and properly configured to interact with the Jira Cloud REST API.