Daniel F
Daniel F

Reputation: 134

How to check if currentDocument is available

I am trying to put some SSJS code together in which I'd like to check, if currentDocument is available.

I've tried something like:

if(currentDocument != undefined)

But it just throws a runtime error.

Is it even possible to check if currentDocument is available?

Any help would be greatly appreciated.

Upvotes: 0

Views: 229

Answers (3)

Maire Kehoe - IBM
Maire Kehoe - IBM

Reputation: 491

This will also work:

if ( requestScope.get('currentDocument') != null )

Upvotes: 0

Tommy Valand
Tommy Valand

Reputation: 868

You almost had it:

if( typeof currentDocument != 'undefined' )

Upvotes: 2

Oliver Busse
Oliver Busse

Reputation: 3395

If also a null check will throw an exception I'd put this in a try-catch block and the catch block to exit with doing nothing (or maybe just logging some information, setting some scope variables to present the user a message etc.)

Upvotes: 3

Related Questions