# Prevent Issue Deletion with Workflows

You can use permissions in YouTrack to control who can delete issues. In some cases, you might want to prevent issue deletion without changing the permission scheme for the project. For example, you might need to apply a temporary restriction or enforce a project-specific policy that is easier to maintain as a workflow.

To prevent users from deleting issues with a workflow, use an on-change rule that is triggered when a user attempts to delete the issue.

```JAVASCRIPT
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
    title: 'Prevent issue deletion',
    guard: (ctx) => {
        return ctx.issue.becomesRemoved;
    },
    action: () => {
        workflow.check(false, 'You are not allowed to delete issues.');
    },
    runOn: {
        removal: true
    },
    requirements: {}
});
```

The `ctx.issue.becomesRemoved` property returns `true` only when the rule is triggered on issue deletion. For this rule to run when a user tries to delete an issue, the `runOn` property must include `removal: true`.

When this rule runs, the `workflow.check` method rolls back the deletion and shows the specified message to the user.

You can extend this rule with additional conditions in the `guard` function. For example, you can allow issue deletion only in specific projects or only for issues that match a particular field value.

## See also

[On-change Rules](on-change-rules.html) [Rule-specific Properties](rule-specific-properties.html)

