I am trying to put some SSJS code together in which I'd like to check, if currentDocument is available.
如果currentDocument可用,我试图将一些SSJS代码放在一起,我想检查它。
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?
甚至可以检查currentDocument是否可用?
Any help would be greatly appreciated.
任何帮助将不胜感激。
3 个解决方案
#1
You almost had it:
你几乎拥有它:
if( typeof currentDocument != 'undefined' )
if(typeof currentDocument!='undefined')
#2
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.)
如果null检查也会抛出异常,我会把它放在try-catch块中,catch块退出时什么都不做(或者只是记录一些信息,设置一些范围变量来向用户显示消息等)
#3
This will also work:
这也有效:
if ( requestScope.get('currentDocument') != null )
#1
You almost had it:
你几乎拥有它:
if( typeof currentDocument != 'undefined' )
if(typeof currentDocument!='undefined')
#2
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.)
如果null检查也会抛出异常,我会把它放在try-catch块中,catch块退出时什么都不做(或者只是记录一些信息,设置一些范围变量来向用户显示消息等)
#3
This will also work:
这也有效:
if ( requestScope.get('currentDocument') != null )