In BCM, custom fields are called user-defined fields (UDF). When a UDF is created, BCM creates entries in several tables to keep track of the new UDF, stores the actual data in binary format and labels the columns UserField# - where # is a number between 1 and 300. In order to access the data stored in a UDF (e.g. for reporting purposes), a user must find the following information:
- FieldGUID associated with user-specified FieldName
- DataType associated with user-specified FieldName
- DataTypeName for the DataType (DataType is same as DataTypeID)
- UserFieldIndex associated with FieldGUID
- EntityType associated with UserFieldIndex
- EntityTypeName for the EntityType (EntityType is same as EntityTypeID)
- SQL Database View of the EntityType which also contains the UDFs
- SQL Database Views containing information related to the EntityType View
- Create SQL Query
- Including Joins of related views
- Using CAST function to view UDF Binary Data
The best way to explain this process is by example. Let’s assume a UDF has been created for the Opportunity form called Test UDF and is of type Date/Time. Now let’s assume we’d like to query the database for a list of Opportunities including the Opportunity Name, Business Contact Name and Test UDF data. We’ll start by collecting the information specified above.
Step 1: Find the FieldGUID associated with Test UDF (user-specified FieldName)
This is located in the SQL Database Table called UserFieldDefinitions
Step 2: Find the DataType associated with user-specified FieldName
This is also located in the SQL Table called UserFieldDefinitions
Step 3: Find the DataTypeName for the DataType
This is located in the SQL Table called UserFieldDataTypes
Step 4: Find the UserFieldIndex associated with the FieldGUID
This is located in the SQL Database Table called EntityUserFields
Step 5: Find the EntityType associated with UserFieldIndex
This is also located in the SQL Database Table called EntityUserFields
Step 6: Find the EntityTypeName for the EntityType (EntityType is same as EntityTypeID)*
This is located in the SQL Database Table called EntityTypesTable
* Some fields may exist in multiple EntityTypes so you’ll need to refer back to step 4 to find the Field associated with the EntityType of interest.
Step 7: Find the SQL Database View of the EntityType which also contains the UDFs
The SQL Database Views that contain “IMAPIView” in the title are the views that contain all the UDFs. In this example, we want to use the OpportunityIMAPIView.
Step 8: Find the SQL Database Views containing information related to the EntityType View
Since the OpportunityIMAPIView only contains the UDFs, we’ll need to also reference the Opportunity View that contains the core fields as well as the Contact View that contains the core fields. In this example, we’ll need the OpportunityFullView and the ContactFullView.
Step 9: Create the SQL Query (including Joins of related Views)
Using Query Designer in SQL Server Management Studio, the final Query looks like this:
CAST(OpportunityIMAPIView.UserField7 AS nvarchar(500)) AS Test_UDF
OpportunityFullView ON OpportunityIMAPIView.ContactServiceID = OpportunityFullView.ContactServiceID
ContactFullView ON OpportunityFullView.ParentEntryID = ContactFullView.EntryGUID
A few final key points:
1. Step 3 was how the DataType was determined for the CAST function. In this example, UserField7 was CAST as nvarchar since the DataType was “Text”. If it had been of DataType “Date Time”, we would have used CAST as datetime.
2. Finally, from Step 4, we determined from the UserFieldIndex that we wanted UserField7 from the OpportunityIMAPIView View.