rrushton Posted April 6, 2019 Report Share Posted April 6, 2019 Hello. Hoping some JS experts here on the forum can help with script for two very similar requests. I am trying to re-direct the user to different pages based on the an record ID in both scenarios. 1. Redirect based on SHIP_ID. If the ship is SHIP_ID # 53, redirect to page x, if the SHIP_ID is not #53, redirect to page y. 2. Redirect based on TOUR_SITE_ID. Tour sites 1, 2, 3, 4, 6 & 8 use one type of report (..../food-plan/..... and Tour Sites 5 & 7 use a different type of report (...../food-grid/.....). I have attempted the following without success: <button onclick="myFunction()">Click me</button> <script> function myFunction() { if(" [@field:TOUR_SITE_ID] " = 1){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =2){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =3){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =4){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =6){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =8){ window.location = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; } else if (" [@field:TOUR_SITE_ID] " =5){ window.location = "https://www.myapp.com/system/food-grid/?RECORD_ID=[@field:RECORD_ID]"; } else (" [@field:TOUR_SITE_ID] " =7){ window.location = "https://www.myapp.com/system/food-grid/?RECORD_ID=[@field:RECORD_ID]"; } } </script> Quote Link to comment Share on other sites More sharing options...
George43 Posted April 8, 2019 Report Share Posted April 8, 2019 Hi there I prepared an example. You can change and add conditions and URL. But logic should work if you will have difficulties just ask me. Href should be changed because they are equal now. <button type="button" id="button[@field:id#]">Click me</button> <script type="text/javascript"> //add field ID with autonmber to your report document.addEventListener('DataPageReady', function (event) { document.getElementById('button[@field:id#]').addEventListener('click',()=>{ //comparing x to y redirection if(+'[@field:SHIP_ID]'==53){ //window.location.href = 'page x url'; //add url links }else{ //window.location.href = 'page y url'; //add url links } //comparing Tour Site switch (+'[@field:TOUR_SITE_ID]') { case 1: case 2: case 3: //you can add case before case 8 case 4: case 6: case 8: window.location.href = "https://www.myapp.com/system/food-plan/?RECORD_ID=[@field:RECORD_ID]"; //url links customization break; case 5://you can add case before case 7 case 7: window.location.href="https://www.myapp.com/system/food-grid/?RECORD_ID=[@field:RECORD_ID]"; break; default: console.log('error'); break; ///etc you can edit cases and so on. } }); }); </script> rrushton 1 Quote Link to comment Share on other sites More sharing options...
rrushton Posted April 10, 2019 Author Report Share Posted April 10, 2019 Hello! Thank you for your assistance with the script. I tried to implement the example for my script but did not have success with the following. Would you kindly point out where I've gone wrong? <button type="button" id="button[@field:RECORD_ID#]">Settle</button> <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { document.getElementById('button[@field:RECORD_ID#]').addEventListener('click',()=>{ if(+'[@field:SHIP_ID]'==53){ //window.location.href = 'app.mysite.com/admin/settlement/otc/?SHIP_ID=[@field:SHIP_ID]&RECORD_ID=[@field:RECORD_ID]&PORT=[@field:PORT]&DATE=[@field:DATE*]'; }else{ //window.location.href = 'app.mysite.com/admin/settlement/ship/?SHIP_ID=[@field:SHIP_ID]&RECORD_ID=[@field:RECORD_ID]&DATE=[@field:DATE*]'; } }); }); </script> Quote Link to comment Share on other sites More sharing options...
George43 Posted April 10, 2019 Report Share Posted April 10, 2019 you should un-comment redirection <button type="button" id="button[@field:RECORD_ID#]">Settle</button> <script type="text/javascript"> document.addEventListener('DataPageReady', function (event) { document.getElementById('button[@field:RECORD_ID#]').addEventListener('click',()=>{ if(+'[@field:SHIP_ID]'==53){ window.location.href = 'app.mysite.com/admin/settlement/otc/?SHIP_ID=[@field:SHIP_ID]&RECORD_ID=[@field:RECORD_ID]&PORT=[@field:PORT]&DATE=[@field:DATE*]'; }else{ window.location.href = 'app.mysite.com/admin/settlement/ship/?SHIP_ID=[@field:SHIP_ID]&RECORD_ID=[@field:RECORD_ID]&DATE=[@field:DATE*]'; } }); }); </script> Quote Link to comment Share on other sites More sharing options...
rrushton Posted April 10, 2019 Author Report Share Posted April 10, 2019 Thank you George. Unfortunately, I still am not getting any result off the script. Quote Link to comment Share on other sites More sharing options...
George43 Posted April 10, 2019 Report Share Posted April 10, 2019 6 hours ago, rrushton said: Thank you George. Unfortunately, I still am not getting any result off the script. Have you checked the names of your fields? Also have uncheckeed HTML Editor? 1) RECORD_ID 2) SHIP_ID Quote Link to comment Share on other sites More sharing options...
rrushton Posted April 10, 2019 Author Report Share Posted April 10, 2019 The HREFs do work as links in separate HTML blocks with RECORD_ID and SHIP_ID fields - those are accurate. HTML Editor is unchecked. Quote Link to comment Share on other sites More sharing options...
George43 Posted April 11, 2019 Report Share Posted April 11, 2019 15 hours ago, rrushton said: The HREFs do work as links in separate HTML blocks with RECORD_ID and SHIP_ID fields - those are accurate. HTML Editor is unchecked. This code designed to work on tabular report in separate block for each record. Quote Link to comment Share on other sites More sharing options...
rrushton Posted April 11, 2019 Author Report Share Posted April 11, 2019 Hi. It is a tabular report, please see screenshot. I am trying to replace the two HTML blocks links "Settle Ruby" and "Settle OTCs" with one link. OTC is SHIP_ID 53 and it has a different settlement process report than all the other ships. 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.