Skip to end of metadata
Go to start of metadata


Required apps

Problem

The problem of this recipe appears when two or more different users try to edit the same issue page. The mechanism explained bellow try to avoid this problem by locking the issue during the edit process and unlocking it at the end of the editing.

Solution

 To solve this problem we offer a solution that use two of our apps: Power Scripts™ for Jira and Power Actions™ for Jira.

The Solution is exemplified on a Jira 5.2.1 environment. In order to resolve it you have to have administrator rights.

Step 1

Create a new Power Actions™ custom field:

  • Go to Administration -> Issues -> Custom Fields and click the link
  • Click the Add Custom Field button
  • Select the Power Actions™ Custom Field and click Next
  • Name it "Disable" and set the desired project you want to lock during the edit process, as shown in the picture:

  • Set your Power Actions™ Custom Field to be visible on all the screens:

  • Configure the "Disable" Custom Field by choosing the cog icon  and selecting the "Configure" option.
  • Add two new buttons by clicking on the "Edit Buttons" link. Name those two buttons: "Lock" and "Unlock":


Step 2

Create a new Custom Field that keeps the username of the user that locked the issue editing.

  • Go back to Administration -> Issues -> Custom Fields and press the link
  • Click the "Add Custom Field" button on the right top of the screen
  • Select the Text Field (< 255 characters) option and click next 
  • Name it "Is Locked" and configure it on the desired projects:

  • Hide this Custom Field by not selecting any of the Screens:

  • Go to Edit Buttons link on the Configure Blitz (Power) Action Custom Field page. As in the previous the step.
  • Press the Edit Screen Script in on the Lock button.

  • Type the following code:

    customfield_10304 = currentUser();
    
    return;

    Where "customfield_10304" is the ID of your "Is Locked" Custom Field. For doing this you have to:

      • Enter Administration section of Jira
      • Go to Issues Tab >> Custom Fields
      • View Field Configurations
      • Hover the mouse over "Edit" link 
      • URL preview at bottom of browser will include fieldID=....
      • The number that is shown is the number you are looking for
  • Go back and press the Edit Screen Script in on the Unlock button. Add the following code:
customfield_10304 = "";
return;

Where "customfield_10304" is the ID of your "Is Locked" Custom Field.

On this step we have connected the buttons we've created to toggle the Is Locked Custom Field when pressing them.


Step 3

Now we have to make the SIL™ script that will do the disable operation during the edit.

  • Go to Administration >> Add-ons >> cPrime Tools
  • Go to SIL™ Manager tab
  • Create a new SIL™ script named "Lock.sil" by clicking on the Show Unused button.
  • Select the folder you prefer and clicNew. Choose File and enter the "Lock.sil" name.
  • Enter the following code in the ""Lock.sil":


if (length(customfield_10304) != 0 && customfield_10304 != currentUser()) {
  lfDialogMessage("Somebody else is editing this issue.", "WARNING");
  lfDisable("issueType");
  lfDisable("priority");
  lfDisable("affectedVersions");
  lfDisable("status");
  lfDisable("resolution");
  lfDisable("summary");
  lfDisable("fixVersions");
  lfDisable("assignee");
  lfDisable("reporter");
  lfDisable("created");
  lfDisable("updated");
  lfDisable("labels");
  lfDisable("editSubmit");
  lfDisable("transitionSubmit");
  lfExecuteJS("ScriptHide.js");
}

lfWatch("customfield_10304", {"customfield_10304"}, "disable.sil");
lfWatch("edit-issue", {}, "disable.sil","click");


  • Create a new SIL script named "disable.sil" and enter the following code:
if (length(customfield_10304) != 0 && customfield_10304 != currentUser()) {
  lfDisable("issueType");
  lfDisable("priority");
  lfDisable("affectedVersions");
  lfDisable("status");
  lfDisable("resolution");
  lfDisable("summary");
  lfDisable("fixVersions");
  lfDisable("assignee");
  lfDisable("reporter");
  lfDisable("created");
  lfDisable("updated");
  lfDisable("labels");
  lfDisable("editSubmit");
  lfDisable("transitionSubmit");
  lfExecuteJS("ScriptHide.js");
}
else {
  lfEnable("issueType");
  lfEnable("priority");
  lfEnable("affectedVersions");
  lfEnable("status");
  lfEnable("resolution");
  lfEnable("summary");
  lfEnable("fixVersions");
  lfEnable("assignee");
  lfEnable("reporter");
  lfEnable("created");
  lfEnable("updated");
  lfEnable("labels");
  lfEnable("editSubmit");
  lfEnable("transitionSubmit");
  lfExecuteJS("ScriptShow.js");
}
  • Add a new file named "ScriptShow.js" and enter the following code:


AJS.$('#rowForcustomfield_10300').show();


  • Add a new file named "ScriptHide.js" and enter the following code:
AJS.$('#rowForcustomfield_10300').hide();

The rowForcustomfield_10300 element represents the custom field ID for the Blitz (Power) Action Custom Field you have created in the First Step. In fact you only have to replace the number with the ID you have.

  • Add the first SIL™ script as a hook on the project you desire.
  • Go to Live Fields tab.
  • Add a new configuration by clicking the "Add configuration" button.
  • Name it whatever you like.
  • Add the Lock.sil script you have just created on the SIL™ File box.
  • Press Add button.
  • Associate this configuration by pressing the Associate link.
  • Select your desired project and click the Associate button.


This is all. You can now test it by opening two different sessions with two different users and try the lock and unlock buttons.

See also

  • No labels