futurist Posted June 27, 2023 Report Share Posted June 27, 2023 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. Quote Link to comment Share on other sites More sharing options...
EileenMG Posted June 28, 2023 Report Share Posted June 28, 2023 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!!) Quote Link to comment Share on other sites More sharing options...
Volomeister Posted June 28, 2023 Report Share Posted June 28, 2023 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> Quote Link to comment Share on other sites More sharing options...
EileenMG Posted June 28, 2023 Report Share Posted June 28, 2023 Thank you -- this works perfectly!! I had a momentary problem with the authfield but that was just an oversight on my part. Thank you so much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.