Skip to end of banner
Go to start of banner

Using AJAX to Hide Issue Links

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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.

  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.

    appendToWebhookResponse(json);
    return true, 200;
  1. Use Live Fields to call the JavaScript file using lfExecuteJS().

    lfExecuteJS("hideLinks.js");

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

    var issueKey =  AJS.$("meta[name='ajs-issue-key']").attr("content");

  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.

    AJS.$.ajax({
        url: "http://<BASE_URL>/rest/keplerrominfo/refapp/latest/webhooks/hideLinks/run?key=" + issueKey
    }).then(function(data) {
        var linkData = data.linkData;
        for ( var i = 0, l = linkData.length; i < l; i=i+2 ) {
            AJS.$("#internal-" + linkData[ i + 1 ] + "_" + linkData[ i ]).hide();
            // console.log(linkData[ i ]);
            // console.log(linkData[ i + 1 ]);
            // console.log("#internal-" + linkData[ i + 1 ] + "_" + linkData[ i ]);
            // console.log("-----------------------");
        }
    });

Filter by label

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

  • No labels