Page 1 of 1

JSM Status and Error Handling

Posted: Wed Mar 29, 2017 4:36 am
by jyoung
In every example I've found in the documentation, after every JSM command the status is checked.
Sometimes, the check just adds a message, sometimes the check adds a message and issues the JSMX_CLOSE command.
However it seems like execution never stops if the status not OK. It just keeps falling through the rest of the commands.
I can understand closing the connection, as that would cause the next command to fail however I don't understand just adding a message.

What is the proper way to handle JSM Status and JSM errors in general? When should I close and when should I leave it?

I've been setting an error status when executing commands like

Code: Select all

mthroutine name(CreatePDF)
define_map for(*RESULT) class(#PRIM_BOLN) name(#hasError)

#hasError := True

* open JSM
#SYS_APPLN.TraceMessageText( "Opening JSM" )
use builtin(JSMX_OPEN) to_get(#JSMXSTS #JSMXMSG #JSMXHDLE)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* load the pdf document service
#JSMXCMD := ('SERVICE_LOAD SERVICE(PDFDOCUMENTSERVICE)')
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* create the document
#JSMXCMD := ('CREATE DOCUMENT(' + #wk_FilePath + ') CONTENT(xml/CMGCCP_Sales_Analysis_Template.xml)')
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* add the header content
#JSMXCMD := ('ADD CONTENT(HEADER)')
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* other content commands omitted

* close the document
#JSMXCMD := CLOSE
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* unload the service
#JSMXCMD := SERVICE_UNLOAD
#SYS_APPLN.TraceMessageData( "Executing &1" #JSMXCMD )
use builtin(JSMX_COMMAND) with_args(#JSMXHDLE #JSMXCMD) to_get(#JSMXSTS #JSMXMSG)
if (#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG ))
return
endif

* close JSM
#SYS_APPLN.TraceMessageText( "Closing JSM" )
use builtin(JSMX_CLOSE) with_args(#JSMXHDLE) to_get(#JSMXSTS #JSMXMSG)
#COM_OWNER.CheckStatus( #JSMXSTS #JSMXMSG )

#hasError := False
endroutine
and checking the status like such

Code: Select all

mthroutine name(CheckStatus)
define_map for(*INPUT) class(#JSMXSTS) name(#status)
define_map for(*INPUT) class(#JSMXMSG) name(#message)
define_map for(*RESULT) class(#PRIM_BOLN) name(#hasError)

#hasError := True

#SYS_APPLN.TraceMessageData( "JSM Status:&1" #status )

if (#status <> OK)
#JSMXSTS := #status
#JSMXMSG := #message
add_entry to_list(#JSMXMessages)

* close JSM
#SYS_APPLN.TraceMessageText( "Closing JSM" )
use builtin(JSMX_CLOSE) with_args(#JSMXHDLE) to_get(#JSMXSTS #JSMXMSG)
return
endif

#hasError := False
endroutine

Re: JSM Status and Error Handling

Posted: Wed Mar 29, 2017 7:59 pm
by HMJust
It really depends on the kind of error you are experiencing, as I could imagine there would be errors you could use to take an alternative path through execution. Like, "if this fails, then I will make this call instead".

However, I think most cases the proper way would be to close the JSM and end the processing. That is what I do.

Re: JSM Status and Error Handling

Posted: Thu Mar 30, 2017 12:49 am
by jyoung
Ok thanks.

That is how I am handling all my operations now, I close the connection if status is not ok and bail out of the processing.

Thanks again.

Joe