Create a clickable link disguised as a Power Action™

Problem

You want to create a link on the issue screen that redirects the user to a customized page (on an external system). The link is typically generated based on the user, their individual permissions, and other issue data.

Solution

Power Actions™ enables you to create buttons for the issue screen and integrate them into the workflow.

The behavior of the buttons created with Power Actions™ can be changed using Power Scripts™ Live Fields. This way, the connection to the Power Actions™ Engine is stopped and a simple link is added using Live Fields. This is done by running a JavaScript code snippet when the issue screen is loaded.

Before you can start using lfSet (button, URL), you must program Power Scripts™ to handle Power Actions™ buttons. This example also provides a reusable JavaScript code snippet for this purpose. Use this code snippet in the Live Fields initialization together with your preferred lfSet() call.

You can create any link you prefer. The link can also be conditionally generated using SIL™. For the purpose of this recipe, a link to the Google homepage has been used.

Before you begin, make sure that:

Step 1 - Create the JavaScript File

When the issue page is loaded, a snippet of JavaScript code is run. This enables you to use the Power Actions™ button with Live Fields in the same way as any other issue field.

Live Fields is programmed to handle the description of the issue when you run lfSet. In the same way, this programmes it to use a specific Power Actions™ button when running lfSet(button, URL).

clickable-link.js
(function(){ /* Descriptor used by Live Fields to know how to do lfSet */ var BAlink = new jjupLF.ExtendedViewSelector("single-select", { view : { setValue : function(fieldId, url){ /* the field ID will come in with the value of linkID */ /* find the link inside the button */ var link = AJS.$("#" + fieldId).find("a.toolbar-trigger"); /* set the new url */ link.attr("href", url); /* [optional] make it open in a new tab. You can skip this to open in the same window */ link.attr("target", "_blank"); } }}); /* we'll call this for each PA button we want to make clickable */ function makeClickableLink(baId, fieldName){ /* generate a unique id for the link*/ var linkID = "jjlf-clickable-" + baId; AJS.$("li.blitz-action[buttonid=" + baId + "]").attr("id", linkID); /* clear the already existing onclick handler */ AJS.$("#" + linkID).attr("onclick", ""); /* register the fieldName with the Live Fields*/ jjupLF.registerDescriptor(fieldName, linkID, "", linkID, BAlink); } /* FILL IN WITH YOUR DATA HERE*/ makeClickableLink(10000, /* 10000 is the id of the Power Action that we want to convert */ "goToGoogle"); /* this is the name we will use in SIL to call lfSet with */ })();

Call the makeClickableLink function at the end of the script above for each button you want to convert. The rest of the script can be used as it is.

The makeClickableLink function takes two parameters:

  • button ID
    This is the ID of the Power Actions™ button. You can retrieve it by searching the selectedValue parameter in the URL of any screens that allow you to edit the button SIL™ scripts. You can find it at the end of the address (for example, /secure/admin/EditBlitzCondition.jspa?[...]selectedValue=10000),

  • field name
    This is the field name used with lfSet. Choose any unique name for this parameter. In this example, goToGoogle has been used.

Copy this script into your silprograms folder.

Step 2 - Configure the Initial Script for Live Fields

Configure the initial script to run the JavaScript code, then set the URL you prefer.

initial-script.sil
lfExecuteJS("clickable-link.js"); string myURL = "http://www.google.com"; // calculate your URL here lfSet("goToGoogle", myURL);