You can set execution trap points in the standard FoD script by using the $set_state command to specify a processing state that will trigger execution of your script starting with the module named in the $set_state command. For more complex applications a $set_state command can trap up to four different states, and you can use the SWITCHFROM system variable to determine which state triggered processing of your script.
Once a $set_state command triggers your script, the system resets the trigger so that reaching any of the states identified in the $set_state command will no longer call your script. The $set_state command is an advanced command and should be used with care. It is often used to trap the call hang up state (entered as either 's:HANG_UP' or 's31') to perform any clean up that needs to be done for a call. This is especially useful in cases where a caller hangs up or a call is disconnected and you need to complete some end of call processing.
Topic url: http://www.copia.com/support/refmanual/index.html?trappingcopiafactsprocessing.htm