How to do issue type validation before creating issue?

I wish to validate the issue type selected before user create issues. How to implement it in jira cloud?

1 Like

Hi @DhineshDhanapal,
I don’t know your exact use case, but it sounds like something that can be solved by using workflow validators.
Connect
Forge
Once the validator is implemented with an expression like issue.issueType.name=="Bug", you need to add it to a proper transition in a project’s workflow, and then it should be possible to create only issues with issue type “Bug”.

Let me know if it was helpful.
Regards,
Beata

2 Likes

Hi @BeataSzturemska

Thanks for your reply. My use case is, I am using openCreateIssueDialog for creating issue and prefilling issue type in that jira create issue dialog. I need to validate the issue type before creating issue or I should not allow the user to change issue type. Can you share the way how to use it?

Thanks,
Dhinesh Dhanapal

Do you need multiple issue types in that project?
If only one issue type is enough, then you can simply limit it in issue type scheme.

Otherwise, I think validators are the way to go.
Than you can build even more complicated expression like
(issue.issueType.name=="Bug" && user.groups.some(group => group=="regular users")) || (issue.issueType.name=="Story" && user.groups.some(group => group=="super users")).

Then members of regular users group can create Bugs only, and super users can create Stories.

I have 5 pages. in each page, I should create one type of issue(only able to create based on the type of the page). I am not depending on the type of users. I hope it will help you to understand the use case.

Regards,
Dhinesh Dhanapal

Now I fully understand you use-case, but I have no clue how to solve it easily.
I’m pretty sure, you can setup some initial value of the issue type, on create issue dialog, but I have no idea how to prevent changes of issue type field. From what I remember, you can’t exclude that field from create issue view.

So the only idea that I have for now is implementing your custom create issue dialog, create the issue with the expected issue type by calling POST /rest/api/3/issue, and passing values read from your custom dialog.

Another option may be creating Jira Service Management project and having multiple forms - separate for every issue type. (I’m sure it’s possible, but I haven’t configured it).

I feel you may give UI modifications a try - here is the full documentation (a guide and fields API is linked within this page): https://developer.atlassian.com/platform/forge/manifest-reference/modules/jira-ui-modifications/

You should be able to apply different modifications on the Global Issue Create form based on context (project + issue type)

Please let me know if you will have some UI modifications questions after reading those docs. Keep in mind it’s for Jira Software only.

Hi @BartoszCytrowski

Thanks for your reference. it is looking like forge app UI modification. is there anything for connect app? It would be great if i have any chance to add validation in connect app create issue modal.

Thanks,
Dhinesh Dhanapal

I’m sorry but I’m afraid I don’t fully understand. What do you mean by “connect app create issue modal”?

UI modifications run within the issue create dialog (modal) and as far as I know, it’s the only way to block the form submission based on its content, available in Jira Cloud.

Can you please clarify what you need or maybe what’s the problem with using Forge here?

@BartoszCytrowski
This is not working when I try to use as follows.
import { uiModificationsApi } from ‘@forge/jira-bridge’;

uiModificationsApi.onChange(({ api, change, uiModifications }) => {
const { current } = change;
if (current.getId() === ‘issuetype’) {
console.log(current.getValue());
}
});
The error occurs:
Uncaught TypeError: Cannot read properties of undefined (reading ‘callBridge’)
at t.getCallBridge (bridge.js:5:28)
at Object. (issue-view.js:8:33)

my application is in connect. Can I use this module inside connect app? Is there any documentation for the need?

my requirement is, I should validate the issue type before creating an issue based on the type of page.

Unfortunately, there is no way of using UI modifications module in the connect app. The way @forge/jira-bridge is built won’t provide the proper iframe communication with 3rd party HTML resource you embed in the iframe.

Then how can we achieve this requirement? what is the proposed solution for this ?

Hi @DhineshDhanapal,

have you tried the approach described by @BeataSzturemska? How to do issue type validation before creating issue? - #6 by BeataSzturemska

If this doesn’t work for you - can you explain why?

If that only the case, then I need to go with it. I am expecting if any handlers as same as “@forge/jira-bridge”, that would be great to use the jira’s native create issue dialog itself.