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

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

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

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:

whatever_name_you_like();

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:

location.reload();

ciao

Hello Roby and thanks so much for suggestions.
Sorry for late responding but I was doing other things… :wink:

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