Using AJAX to Hide Issue Links

Peacock

A common use case users ask for is to be able to hide links based on certain criteria. However, to pass information from a SIL Script to JavaScript requires calling a SIL Webhook via AJAX.

Part 1 - Create a SIL Webhook

  1. At the very top of the script, define the kind of link type you would like to hide.

    string [] issueLinkTypeName = {"Relates"};

     

  2. Next add a basic webhook. For detailed information on SIL Webhooks, see this documentation on Webhooks configuration.

    WebhookPayload httpRequestPayload = getWebhookPayload(); string httpMethod = httpRequestPayload.httpMethod; string httpPayload = httpRequestPayload.payload; WebhookParam[] httpQueryParams = httpRequestPayload.queryParams; // string firstQueryParamName = httpQueryParams[0].name; string issueKey = httpQueryParams[0].values[0];

     

  3. Next, structure your basic JSON response by adding link data to those links you want to hide. The idea here is to return alternating values of the issue id (link.id)and link id (link.issue.id). For more details on available variables, see this documentation on predefined structure types for JIssueLink.

    string [] result; JIssueLink [] links = getIssueLinksDetail(issueKey); for (JIssueLink link in links) { if (arrayElementExists(issueLinkTypeName, link.name)) { result += link.id; result += link.issue.id; } } result = replace(result, "|", ","); string json = "{\"linkData\":"; json += "["; json += result; json += "]}"; runnerLog(json);

     

  4. Lastly, append the json data to the response and respond.

Part 2 - Configuring the JavaScript

  1. Use Live Fields to call the JavaScript file using lfExecuteJS().

     

  2. In “hideLinks.js”, use the attr() jQuery function to get the issue context for the page.

     

  3. Next, add the ajax call. The following script calls the webhook we created and then uses the data (issue and link ids) to hide the desired links using the hide() function.

Related articles

Filter by label

There are no items with the selected labels at this time.