Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Restrict Issue Type Change During “Move”

Pandey_ Anil _Non-Kenvue_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 31, 2025

Prevent converting a Test Execution to another issue type when there is a test run

Hi All using below code I saw its working in log but how can I restrict the move if I have test runs

I shared the below code that's not restricting the move click but issue got reset after final changes

async function checkTestRuns(issueId, token) {
const query = `
query ($issueId: String!) {
getTestExecution(issueId: $issueId) {
testRuns(limit: 10) {
total
results {
id
status { name }
test { jira(fields: ["key", "summary"]) }
}
}
}
}
`;

const response = await api.fetch('https://xray.cloud.getxray.app/api/v2/graphql', {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query, variables: { issueId } })
});

if (!response.ok) {
console.error('❌ Failed to fetch test runs:', await response.text());
return false;
}

const data = await response.json();
console.log("data",JSON.stringify(data))
const total = data?.data?.getTestExecution?.testRuns?.total || 0;
return total > 0;
}

// Check if issue type changed from Test Execution while test runs exist
export async function validateIssueTypeChange(event, token) {
const issueId = event?.issue?.id;
const changelog = event?.changelog?.items || [];
const issueTypeChange = changelog.find(i => i.field === 'issuetype');

const fromTypeId = issueTypeChange?.from;
const toTypeId = issueTypeChange?.to;
const currentTypeName = event.issue.fields.issuetype?.name;

console.log('Type change:', { fromTypeId, toTypeId, currentTypeName });

// Only validate if moving away from Test Execution

if (fromTypeId && toTypeId && currentTypeName !== 'Xray Test Execution') {
    const hasRuns = await checkTestRuns(issueId, token);
    if (hasRuns) {
      console.log('🚫 Issue type conversion blocked due to existing test runs.');

        await api.asApp().requestJira(route`/rest/api/3/issue/${issueId}`, {
        method: 'PUT',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          fields: {
            issuetype: { name: 'Xray Test Execution' }
          }
        })
      });
      return {
        success: false,
        message: '❌ Cannot convert Test Execution to another issue type while test runs exist.'
      };

    }
    else {      
return { success: true };
    }
  }

// Main validator entry point
export async function run(event) {
console.log('Incoming event:', JSON.stringify(event, null, 2));
//const issueId = event?.issue?.id;
const token = XRAY_TOKEN;

const typeChangeResult = await validateIssueTypeChange(event, token);
console.log("typeChangeResult",typeChangeResult)
if (!typeChangeResult) return typeChangeResult;


}

 

1 answer

0 votes
Nikola Perisic
Community Champion
July 31, 2025

Welcome @Pandey_ Anil _Non-Kenvue_ 

I'd suggest to use an easier approach which is adding a property to your workflow on your moving transition:

Key: jira.permission.edit.denied

Value: leave it empty

Pandey_ Anil _Non-Kenvue_
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 31, 2025

Hi @Nikola Perisic  thanks for quick reply, I just want to restrict this area using my plugins, its possible see attachments? as I have fixed for transitionimage.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events