Restrict subtask per issue type

Manar El Kefi July 25, 2024

Hello , I want a solution to restrict  the creation of subtasks per issue type.

 

I tried to create a forge app but nothing changes. here is my manifest.yml:

 

modules:
  trigger:
    - key: issue-subtask-hello-world
      function: main
      events:
        - jira:issue_created
  function:
    - key: main
      handler: index.run
app:
  runtime:
    name: nodejs18.x
  id: ari:cloud:ecosystem::app/0aeac7b4-4bf2-4d2b-a6a3-1cfc22bd81b3                            
and index.jsx : 

 

export async function run(event, context) {
    console.log('Trigger Event:', event);

    const issue = event.issue;
    const parentIssueId = issue.fields.parent?.id;
 
    if (parentIssueId) {
      try {
        // Fetch parent issue details
        const response = await fetch(`/rest/api/3/issue/${parentIssueId}`);
        const parentIssue = await response.json();
 
        const allowedIssueTypes = ['Story', 'Task'];
 
        if (!allowedIssueTypes.includes(parentIssue.fields.issuetype.name)) {
 
          await fetch(`/rest/api/3/issue/${issue.id}`, {
            method: 'DELETE',
            headers: {
              'Content-Type': 'application/json'
            }
          });
          console.log(`Subtask ${issue.key} deleted because its parent issue type is not allowed.`);
        }
      } catch (error) {
        console.error('Error handling issue:', error);
      }
    } else {
      console.log(`No parent issue found for ${issue.key}.`);
    }}

 

If there is another solution please let me know.

1 answer

0 votes
Charlie Misonne
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 26, 2024

I don't know about that but you might be more lucky on the developer community :-)

The Atlassian Developer Community

Suggest an answer

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

Atlassian Community Events