ScriptRunner Web Fragments to change UI to disable cloning in 1 project?

WP Service Account May 11, 2016

Hi,

Does anyone know if it is possible to use the new Web Fragments feature of ScriptRunner to alter the UI to prevent issue cloning in just 1 project? And if so, how?

Thanks in advance

Conor

3 answers

1 accepted

0 votes
Answer accepted
Mark McCormack _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 19, 2016

Hi Conor,

Our latest release includes a built-in script to allow you to conditionally hide UI elements (like the Clone button):

https://scriptrunner.adaptavist.com/4.1.3.16/jira/fragments/HideUIElement.html (for JIRA 6.3/6.4)

https://scriptrunner.adaptavist.com/4.3.5/jira/fragments/HideUIElement.html (for JIRA 7.x)

I hope you like it.

regards, Mark.

WP Service Account July 19, 2016

Thank you Mark! This is exactly what i needed.

I've implemented this for 1 of our projects and it works great!!

Super support as always from you guys smile

roniz November 28, 2017

Hi Mark McCormack

I'm having some difficulty in finding how to get to go to Admin → Script Fragments

 

can you help me find it?

Mark McCormack _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 30, 2017

Sure thing: please try the Jira Admin (cog) --> Add-ons then find the ScriptRunner section and finally choose Script Fragments.

Alternatively you could try using "." (or even "g+g" or press g twice) and then type "Script Fragments".

I hope that helps.

roniz December 6, 2017

thanks!!

1 vote
rahuldanwade
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 5, 2017

Hi

Not sure if you already implemented this.

1. Click on Hide system or plugin UI element 

2. type com.atlassian.jira.plugin.system.issueoperations:clone-issue in what to hide (Module key)

3. Put this condition !(jiraHelper.project?.key == "Project_Key") 

Save

1 vote
Ashraful Hasan [Adaptavist] May 13, 2016

Hi,

The following script should hide "Clone" menu item for one project only. Tested in JIRA 7 and works fine.

  1. Select ScriptRunner "Script Fragments -> Install web resource". Provide details [screenshot attached]:hide-clone.png

    You can also check ScriptRunner web resources from here: https://scriptrunner.adaptavist.com/latest/jira/fragments/WebResource.html

  2. The javascript file "hide-jra.js" contains the following code:

    (function ($) {
    
        $(function () {
            /**
             * Binding is required for link such as
             * http://localhost:8080/jira/projects/JRA/issues/JRA-4?filter=allopenissues
             */
            JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(event, $context, reason) {
                if (reason === JIRA.CONTENT_ADDED_REASON.pageLoad || reason === JIRA.CONTENT_ADDED_REASON.panelRefreshed ) {
                    hideCloneMenuItem();
                }
            });
    
            //calling function for link such as: http://localhost:8080/jira/browse/JRA-5
            hideCloneMenuItem();
        });
    
    
        /**
         * Hide the clone menu
         */
        function hideCloneMenuItem() {
            var projectKey = "JRA";
            var issue = JIRA.Issue.getIssueKey();
            if (typeof (issue) !== "undefined") {
                var currentProject = issue.substr(0, issue.indexOf('-'));
                if (currentProject == projectKey) {
                    $("a#clone-issue").hide();
                }
            }
        }
    }) (AJS.$);

     

    I have used project key "JRA" for this example. 

WP Service Account May 18, 2016

Hi Ashraful,

I have the following based on your answer above -

  • created the script resource dir,
  • added the js script to it (updated the project key)
  • updated the setenv.sh args to pick up new directory
  • restarted JIRA
  • and added the web resource.

Unfortunately this does nothing (other than not throw an error, which at least confirms it's picking up my resource directory).

I'm running JIRA 6.4.7 (our org. is not able/ready to upgrade to JIRA 7 just yet)

Any ideas?

Kind regards

Conor

 

 

 

Ashraful Hasan [Adaptavist] May 19, 2016

Hi - the script has been updated and it works fine in JIRA 6.4.7. I have removed "AJS.toInit" from 2nd line. After uploading the script you may need to restart the JIRA instance.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events