It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Hide some workflow buttons permanently from users using jquery or JS

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

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 Feb 19, 2019

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

0 votes
Andy Heinzer Atlassian Team Feb 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?

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

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 Dec 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.

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you