Announcement

Collapse
No announcement yet.

How write if else test into JS Button

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How write if else test into JS Button

    Hello
    On JS Button I had this code that worked fine . It cleans the page and reset all filters

    {window.location.href="../grid_pipeline/grid_pipeline.php" ;}

    Now I have to make a "if else "depending on the user's grant like this one


    if ([glo_limited_view]=='Y')
    {window.location.href="../grid_pipeline_limited/grid_pipeline_limited.php" ;}
    else
    {window.location.href="../grid_pipeline/grid_pipeline.php" ;}

    The JS sintax is for sure uncorrect ... and the button stopped to work.
    I suppose the problem is within

    if ([glo_limited_view]=='Y')

    that in JS maybe has to be written in another way.... (the global variable [glo_limited_view] in JS ?? )

    How do I write the if else into js button ?
    Thanks
    Last edited by giovannino; 09-20-2018, 09:09 AM.

  • #2
    I think you need quotes around the global variable as well:

    Code:
    if ('[glo_limited_view]' == 'Y')

    But in case the SC parser will ignore global variables inside the JS buttons, you can do this:

    in the onscriptinit event

    Code:
    echo "<script>
    function whatever_name_you_like()
    {
      ... <-- move here the JS code you now have in the button, changing all double quotes (") to single quotes (')
    }
    </script>";
    So the SC parser should now handle the [] variable correctly.

    Then in the JS button you need just one line:

    Code:
    whatever_name_you_like();
    Last edited by robydago; 09-20-2018, 02:44 PM.

    Comment


    • #3
      Btw,

      if you're actually reloading the same php page and not changing it, you could just use this line in your js button and it will work regardless of the grid app url:

      Code:
      location.reload();

      ciao

      Comment


      • #4
        Hello Roby and thanks so much for suggestions.
        Sorry for late responding but I was doing other things.. ;-)

        I adoped for the moment the easiest one
        if ('[glo_limited_view]' == 'Y') and seems to work ;-)) Bye Giovanni

        Comment

        Working...
        X