Jump to content

Destination of Link Varies Depending on Value of Aggregate


Recommended Posts

Hi,

Just wanna share this code that I came up with where I have a Tabulare Report with Totals & Aggregations and a link at the footer of the DataPage wherein that link's destination URL will depend on the value of the Aggregate. In this example, if the Aggregate has a value of zero, the link will lead you to URL1, but if it has a value that is greater than zero, it will lead you to URL 2. 

 

The first thing you're gonna want to add is the link on the footer (it could also be in the header, does not matter):

    <a id="conditionalbutton">CONDITIONAL BUTTON</a>

You can change this up to however you want but you have to make sure to keep in the id="conditionalbutton" part. This is important because this is what the JavaScript (provided in the next step) will be referring to when assigning the appropriate URL to the link depending on the Aggregate value.

Below is the JavaScript code (which you'll paste on the footer):

 

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {

        var agg = document.querySelector(".cbResultSetTotalsDataCellNumberDate").innerHTML
        var cb = document.querySelector("#conditionalbutton")
    if(Number(agg) > 0){
        cb.href = "www.google.com"
        }else{
        cb.href = "www.facebook.com"
        }
});
</script>

 

You can replace the URLs as you see fit. In the above example, replace "www.google.com" with the URL that you want for the link if the Aggregate has a value greater than zero. Replace "www.facebook.com" with the URL that you want for the link if the Aggregate;s value is zero.

Link to comment
Share on other sites

I saw your title "Destination of Link...depending on..." and got all hopeful that I could use your code to add a link to the header - but my "depending on" part is very different. 

All I want is the two destination links based on the number found in [@authfield:t1_b2].  1=google.com  else facebook.com like your example

I thought it would be so simple but no matter what I try I can't get it to work.  Help please? (yes, i'm new at this, so any help is appreciated!!)

 

Link to comment
Share on other sites

Hi @EileenMG

You can try this version for your condition

<a id="conditionalbutton">CONDITIONAL BUTTON</a>

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
        var cb = document.querySelector("#conditionalbutton")
    if(Number([@authfield:t1_b2]) == 1){
        cb.href = "www.google.com"
        }else{
        cb.href = "www.facebook.com"
        }
});
</script>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...