Hide some workflow buttons permanently from users using jquery or JS

Bhupesh Nagda February 7, 2019

Hi All,

I need to keep certain workflow buttons hidden from all users permanently as these buttons(transitions) will be called by an external system using JIRA REST API.

I am having really hard time to find out a concrete way of doing this. I tried to use hide transition from user workflow condition but the condition always fails.

So in the end I had to try Jquery in Announcement banner: 

It helped me to hide the buttons for initial page load but whenever there is a transition happening on ticket the hidden buttons show again. I am using below code. I am no expert in Javascript or Jquery so maybe i am missing something silly. I have the exact action ids which should be hidden always.

<script type="text/javascript">

(function($) {
$(document).ready(function() {


if($("#project-name-val").html()=="XYZ"){

$("#action_id_181").hide();
$("#action_id_71").hide();

//more such action ids which should be hidden


}

});
})(AJS.$);
</script>

I tried to use some more additional conditions below this code like when transition is 'assign in jira' then reload the page so that the ready function is executed and buttons hide again but there may be some better way of doing it.

 

if($("#issue-workflow-transition-submit").html()=="Assign In JIRA")
{
location.reload();
}
}

 if someone has any insights or suggestions please help!

 

Cheers,

Bhupesh

 

2 answers

1 accepted

3 votes
Answer accepted
Bhupesh Nagda February 18, 2019

With a little more effort and help from a jquery expert i was able to get it working. 

Working code:

 

<script type="text/javascript">
(function($) {

$(document).ready(function() {

setInterval(function() {

if($("#project-name-val").html()=="XYZ"){

$("#action_id_31").hide();
$("#action_id_181").hide();
$("#action_id_71").hide();
$("#action_id_181").hide();
$("#action_id_11").hide();
$("#action_id_121").hide();
$("#action_id_21").hide();
$("#action_id_251").hide();
$("#action_id_81").hide();
$("#action_id_271").hide();
$("#action_id_291").hide();

}

},500);

});
})(AJS.$);
</script>

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 19, 2019

Thanks for updating the thread with your solution.   Would you mind sharing the details of your javascript?

Rodolfo So April 1, 2021

Hi @Bhupesh Nagda 

 

Can you able to provide screenshot the script that you paste in Jira announcement banner. I tried to copy your scrip and replace the project name and action but didn't works. 

 

Appreciate your help on this

1 vote
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 15, 2019

There are times when I've recommended using a javascript hack in Jira to hide elements on the page.  However in your case, I don't think this is really the best approach given what you told us so far.  I understand most of your users only use Jira via the webpage, but technically they are not restricted from making REST API calls themselves.  So a Javascript approach isn't really full proof solution here.

I think instead the better solution to prevent users from doing this would be to utilizing workflow conditions.  These are built into Jira workflows.   In your case, I would recommend creating a group in Jira's user management, specifically to be used by your REST API user(s).   Once you assign the Jira user(s) to that group that should be able to make these transition, you can then edit the workflow in use by that project, edit that transition and set a condition of "User in group", and select that group name.

Once you publish this workflow, then the only way a user could see that transition in Jira would be if they were a member of that specific group.

 

You mentioned that you tried this previously but that the condition is always failing.  Can you tell us more about what condition you selected, and how you configured it here?

Bhupesh Nagda February 18, 2019

Hi Andrew,

 

Thank you for your reply!

Background: JIRA<==>Remedy ticket syncing integration

I considered the option to use workflow conditions and using groups. However, we cannot restrict based on user group because typically any user can create ticket from remedy and then to JIRA via scripted APIs so we have to keep it open to all users.

 

BR,

Bhupesh

badana_teja December 9, 2019

Hello there,

I just want to hide the edit button for Closed status issues. Is this possible with putting javascript in announcement banner ? If yes, please assist me on code.

 

Thanks,

Tej

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 10, 2019

@badana_teja For that use case, you don't need to use javascript to do this.  This is something you can do as a workflow property.  Check out the KB Issues are Editable In Closed State 

By adding that property to the workflow and then publishing the workflow, issues in that state that use that workflow will not be able to be edited when in a closed state.

badana_teja December 10, 2019

Hi Andy Heinzer,

I understood your suggestion, but we would likely to allow worklog enterings after setting this property on close transition. I see, there is no option to disable edit and allow worklogs, so the only workaround I could think of is to add some Javascript code to the Jira announcement banner, since any code added to it will be executed on any Jira page. What we could do is write some code that will hide the Edit button based on the current status of the issue and allows the worklog entering as well.

 

Thanks,

B.S.Teja

Aayush Mohanka December 23, 2020

Hi Andy,

I was trying to make a transition which is hidden from the user using Rest API call, how can I do that.
Your suggest of adding user to group seem less effective as my Rest API user and logged-in user will always be same.

I am trying to differentiated whether the event reached my plugin was triggerd by UI or API

Suggest an answer

Log in or Sign up to answer