Question

OOTB function pxDoesHandleExist fails if parameter passed is not a valid handle

The built-in pega function 'pxDoesHandleExist' returns 'true' if the handle exists, as expected.

However, if the parameter passed is 'garbage,' for example - the function fails rather than returning 'false' - with the message "

 Class GARBAGE does not exist 

This does not fit with the use case given in the help file - where this function is meant to be used as a precondition for obj-open-by-handle so we can avoid trying to open a nonexistent instance of a rule.

Screenshot attached, please advise.

**Moderation Team has archived post**

This post has been archived for educational purposes. Contents and links will no longer be updated. If you have the same/similar question, please write a new post.

Correct Answer
June 5, 2018 - 2:44pm

Thanks, Susan!

I finally got around to opening a ticket with Pega Support - SR-C37427. - and they gave me a fix that worked well.

Basically we return false when the database exception is thrown by the call to doesInstanceExist() - rather than propagate the exception up.

Note that because a hotfix was not provided, I had to change the name of the function and save it in our custom library.

Comments

Keep up to date on this post and subscribe to comments

Pega
March 15, 2018 - 6:50pm

Hi,

I would think that this is an expected behavior.

The funciton returns true if an object with the given handle exists, false otherwise. If an error is encountered checking for the object, a runtime exception is thrown.

Below is the documentation for "doesInstanceExist" (you can view it from the Pega developer portal with > engine api > Database class). Based on this, if an error is encountered,  you will get an exception instead of a boolean "false" return.

boolean doesInstanceExist(java.lang.String aInstanceHandle)
                          throws DatabaseException

Indicates whether a particular instance exists in the database.

This method does not perform any security checking.

Parameters:
aInstanceHandle - the handle (pzInsKey) of the instance
Returns:
true iff the instance exists
Throws:
BadClassDefinitionException - if the instance has an invalid pxObjClass. The processing status is set to error if this is the case.
ConfigurationException - if the database table configuration is bad
DatabaseException - if something else goes wrong
 

March 16, 2018 - 1:25pm
Response to SusanLiu

Hi Susan,

Thanks for the response.

The behavior for doesInstanceExist seems to match the documentation - since it states that it returns 'true' on success and that it throws an exception on failure.

But pxDoesHandleExist demonstrates incorrect behavior.

It is meant to be used, as per the documentation, as a precondition for objbrowsebyhandle -but it can't work for that use case since the failure is not trappable as an exception.

https://pdn.pega.com/sites/pdn.pega.com/files/help_v731/procomhelpmain.htm#engine/database/tables/eng-db-does-handle-exist-tsk.htm

"The pxDoesHandleExist function accepts as a single parameter, a text value containing the candidate handle, and returns true or false." 

 

Pega
March 28, 2018 - 2:28am

Hi,

If you open Function "pxDoesHandleExist", under History tab, Usage: "Returns true if an object with the given handle exists, false otherwise. If an error is encountered checking for the object, a runtime exception is thrown."

If this Function never returns a false for an un-valid handle, please go ahead to raise a SR. We will do further research on this and decide if online help for this needs to be modified. 

https://pdn.pega.com/sites/pdn.pega.com/files/help_v731/procomhelpmain.htm#engine/database/tables/eng-db-does-handle-exist-tsk.htm

Thanks,

Susan

June 5, 2018 - 2:44pm
Response to SusanLiu

Thanks, Susan!

I finally got around to opening a ticket with Pega Support - SR-C37427. - and they gave me a fix that worked well.

Basically we return false when the database exception is thrown by the call to doesInstanceExist() - rather than propagate the exception up.

Note that because a hotfix was not provided, I had to change the name of the function and save it in our custom library.