Desktop User Guides > Professional > Data management scripting > Data Management Script (DMS) file > Sections in the DMS file > Event section > OnBadCase Event section
 
OnBadCase Event section
The OnBadCase Event section defines procedural code that is to be executed for each “bad” case, that is, a record that will not be transferred to the output data source because it has failed the validation. You typically use the OnBadCase event section to create a report of bad cases, for example, by writing the details of the invalid record to a text file. You could then email the text file in the OnJobEnd event section.
You cannot use the OnBadCase event to correct the error or errors that caused the record to fail validation. If you want to clean your records during the transfer, use the OnNextCaseEvent section (see OnNextCase Event section). Also, if your data management script includes a Logging section (see Logging section, full details of each bad record are written to the log.
Depending on the options set for the data transfer, the OnBadCase event might not be executed for some or all records that contain errors. For more information, see Validation options when transferring data.
The OnBadCase Event section is available only when you have specified an input metadata source. If you try to include an OnBadCase Event section in a case data-only transformation or when using a non-UNICOM Intelligence Data Model OLE DB provider, you will typically get an “Object reference not set to an instance of an object” error.
For information about accessing objects in this section, see Using objects in the Event section.
Example
This example writes a message to a text file for each bad case. The message includes the value of the record's Respondent.Serial variable.
The example also increments a count of bad cases, which will be written to the text file in the OnJobEnd event. The count of bad cases is stored in a global variable called BadCaseTotal.
Event (OnBadCase, "Output details of the bad case")
' For each bad case, write a message to the text
' file and the console...
Dim txtmsg
txtmsg = "Bad case - Record not transferred for respondent: " + _
CText(Respondent.Serial)
dmgrGlobal.MyTextFile.WriteLine(txtmsg)
Debug.Log(txtmsg)

' Increment the count of bad cases...
dmgrGlobal.BadCaseTotal = dmgrGlobal.BadCaseTotal + 1
End Event
This example is part of a sample DMS file called OnBadCase.dms, which is installed with the UNICOM Intelligence Developer Documentation Library. For more information, see Sample DMS files.
See
Event section