Tech Tip: How to check if a Named Selection exists
PRODUCT: 4D | VERSION: 14.0 | PLATFORM: Mac & Win
Published On: September 11, 2014
Validating if a Named Selection exists is useful to make sure errors are handled properly. While there isn't a simple method like using If (Records in set("Set_Name")>0) to check that the set exists below is a simple method that can see if the Named Selection is valid.
The Method is composed of two parts and uses the ON ERR CALL to handle the error alert.
C_LONGINT(Error_Code) Error_Code:=0 ON ERR CALL("Error_Method") USE NAMED SELECTION("Selection_Name") //or a different command with use of a named selection ON ERR CALL("") |
Error_Method:
If(Error_Code=0) ... //No error Else ... //Error was found, place code to handle this error End if |
The provided code above is only a general outline, in the Error_Method it may be useful to create more than one for multiple situations and the first method can replace USE NAMED SELECTION with CREATE NAMED SELECTION to force an error if it exists or confirm that the Named Selection does not exist.