Compute which Xpage to open

Hi,

I’d like to open different Xpages from a button on a Custom Control, based on the current URL.

On the onClick event of the button I selected “Open Page” then I added the following script to the “Name of Page to Open”:

var str = context.getUrl();

var xpg = “xpages1.xsp”;

if (str.indexOf(xpg) > 1) {“xpages2.xsp”}

else {“xpages3.xsp”}

The selected language is “JavaScript (server side)”

I just can’t get it work…

Thank you for your help,

Etyien

Subject: Convert the url to a string type

As far as I remember reading, in 8.5 getUrl would return a string but this was actually incorrect and it should have returned an object of a class. They have since fixed this in 8.5.1+.

If you wrap your str variable in @Text or use toString (if you don;t want to use @Formula) that should fix it for you.

var str = @Text(context.getUrl());

var xpg = “xpages1.xsp”;

if (str.indexOf(xpg) > 1) {“xpages2.xsp”}

else {“xpages3.xsp”}