Jump to content

Redirect Based on ID in Tabular Report(s)


Recommended Posts

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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

 

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...