In our Jira Board, when we right click an issue card, it shows options to Archive or Delete the issue.
Is it possible to hide these options using Scriptrunner Fragments or something ?
The reason is because, we currently have a condition where only completed issues can be archived. But, this Board option defies that condition and enables users to archive any issue irrespective of its status. So, want to limit that.
Hi @Aisha M
Thanks for mentioning me.
Yes, you can hide the "Archive" and "Delete" options using ScriptRunner Fragments.
- Go to ScriptRunner in your Jira instance.
- Navigate to Scripted Fragments and create a new fragment
- Select Hide UI element
- select "com.atlassian.jira.plugin.system.issueoperations:archive-issue"
and "com.atlassian.jira.plugin.system.issueoperations:delete-issue" options.
Please let me know if you have further questions
Best,
Tuncay
@Tuncay Senturk Thank you sooo much for getting back !
Actually we do have a fragment to hide the 'Archive" option from issues. Basically, archive option will be available only when an issue is in the resolved status.
But despite having this fragment, I observed users can still archive an issue from the Board context menu.
So, even if I hide the archive element with com.atlassian.jira.plugin.system.issueoperations:archive-issue the issue can still be archived by right clicking the issue from the board and selecting "archive"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry for the misunderstanding.
I think the actions that come with the board are not selectable in the fragment so I cannot offer any solution on this.
I'm not entirely sure if this is a good approach, but you could create a listener that checks for the Archive action and prevents it when the issue's status doesn't meet your criteria. Please take this suggestion with a pinch of salt, as I haven't personally tried it. However, if I were in your position, I would give it a try with a code something like below.
def issue = event.issue as Issue
def status = issue.getStatus().getName()
if (status != "Resolved") {
log.warn("Archiving is only allowed for issues in 'Resolved' status. Action blocked.")
// throw an exception to prevent the action
throw new IllegalStateException("Cannot archive issue as it is not in Resolved status.")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk Let me try the approach with the listener. Unable to reply to your latest comment (not sure why)
But this also means there is not guarantee that the archive action will be prevented from the Board context menu, right ? :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using a listener to prevent actions is the back-end solution. This listener will stop users from archiving or deleting an issue, whether they are using a UI button, a REST service, or any other method. You can remove the link from UI but users may still call the back-end service using REST or do some hacking via UI. Think of it as insurance - if you forget to remove a link, the listener will take care of it.
But, like I said, this might not be the best approach.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried it with the below listener. But, unfortunately, it runs AFTER the issue is archived from the context menu and shows as failed in the logs . I have tried it with events - Issue updated & all issue events
def log1 = Logger.getLogger("PreventArchiving")
def event1 = event as IssueEvent
log1.info("Listener executed for event: ${event1.eventTypeId}")
def issue = event1.issue as MutableIssue
if (issue) {
ArchivedIssueService archivedIssueService = ComponentAccessor.getComponent(ArchivedIssueService)
def status = issue.status.name
log1.info("Attempting to archive issue ${issue.key} with status ${status}")
if (status != 'Resolved') {
log1.warn("Preventing archive action for issue ${issue.key} with status ${status}")
throw new Exception("Issue ${issue.key} cannot be archived because it is not in a resolved state.")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, that's bad news. I was thinking that it might have worked as an interceptor.
Sorry, I wasn't helpful on this one. Let me think about it and write back if I find something useful.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No no, you were super helpful in giving me suggestion to think outside the box :):)
Thank you ! But I must add, I also come across this ticket https://jira.atlassian.com/browse/JSWSERVER-9557 - Looks like there isn't must flexibility with the context menu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M
I could not find a better solution but to limit/restrict users as @Antoine Berry mentioned. Sorry!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for checking back :)
Actually my org just recently gave EVERY USER the right to archive resolved issues . . lol
But I also came across this after some digging, https://community.atlassian.com/t5/Jira-questions/Hide-entrys-from-scrum-kanban-board-context-menu-via-javascript/qaq-p/1431344 . . Maybe will test this out :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, you can also perform that trick, but you need to check it every time you update Jira because they might change the CSS class or the identifier that you use to hide the web element.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I was able to successfully hide Archive by using javascript in the announcement banner *yayyy*
But, when you say the identifier might change, it means we might have to update the script only when we upgrade the version of Jira, right ? Also, do you think this method might hamper any other functionality within Jira . . We have a hugeeee number of projects & users, so just want to make sure I'm not overlooking anything else that might break because of this minor change :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad you figured that out, @Aisha! That's great news. The impact of the script depends on the selector you use. For example, the script in the thread you mentioned (below I copied a snippet) uses an id (starts with #), and id values are unique, so it won't impact other HTML elements.
$("#ghx-issue-ctx-action-flag-toggle").css("display", "none");
However, sometimes people use selectors with CSS classes (starting with .) that can be applied to various elements. As a result, all elements that use that class would be affected.
$(".a-css-class").css("display", "none");
Also, these are the design values that Jira developers use. They may change them in the upcoming releases. In those circumstances, you need to check and update the scripts accordingly after upgrading your Jira.
If you share your code, I might be a little more helpful, I guess.
I hope that helps.
Best
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oooh makes sense . . I used the chrome inspect tool to find the element for the context menu archive option.
<script>
if (document.URL.indexOf("RapidBoard.jspa") >= 0) {
AJS.$ (document).on("showLayer", function() {
$("#ghx-issue-ctx-action-archive").css("display", "none") ;
});
}
</script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
#ghx-issue-ctx-action-archive
this is good, it's the id value :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
SOLUTION -
Adding a javascript to the Announcement banner
<script>
if (document.URL.indexOf("RapidBoard.jspa") >= 0) {
AJS.$ (document).on("showLayer", function() {
$("#ghx-issue-ctx-action-archive").css("display", "none") ;
});
}
</script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Aisha M ,
Have you considered restricting the Archive and Delete permissions to only the project admins ? That would also be in line with best practices. That would prevent your users to delete an issue by mistake, and then it is gone forever.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hellooo :) Actually our org have given every user the permission to archive any resolved issue. For the other statuses, the Archive option will be hidden. Now, they want to understand if users can archive issues from the board context menu. And from my testing, I can conclude anybody can archive issues from the context menu irrespective of the status .
I also came across this old question https://community.atlassian.com/t5/Jira-questions/Hide-entrys-from-scrum-kanban-board-context-menu-via-javascript/qaq-p/1431344 This person had hidden an option from the context menu through the announcement banner. Curious to see how this goes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tuncay Senturk Hellooo, Hope you are well and good :) Can you please help me with your suggestion/
I am just looking for ways to hide elements from the Board context menu (Right click on the card) . . Is it possible to hide the Archive & Delete options from them ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much @Tuncay Senturk & @Antoine Berry for your suggestions. It really helped me think of other perspectives for figuring out a solution. Also, I have accepted both your answers since, both of them contained solution that could be used for similar scenario :):)
On a side note, my team has dropped this request and hence I have now moved on to a different problem related to workflows . . ;(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In case anyone wants to look - https://community.atlassian.com/t5/App-Central-questions/Need-help-with-clearing-issue-Resolution-through-ScriptRunner/qaq-p/2834649
I will take any help ! :D
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.