Introduction
Attributes are sometimes described as the junk drawer of the database. Attributes, however, can be very useful for a variety of reasons. They are easy to set up with no coding required, have a lot of flexibility with data types and are easy for end users to understand. This type flexibility can come at a price. The underlying data structure is complex and difficult sometimes to work with for customizations. Nonetheless, attributes are a useful tool for your organization.
Many organizations have found that attributes lack the ability to set the default value. In Blackbaud CRM™ design mode this can be worked around by adding a custom action button and creating a default value in the parameters. The downside is that each configured attribute-add action would need its own button. If you have a lot of attributes this would become unwieldy.
But with some customization, we can create a more flexible way of managing attribute defaults. This article is a proof-of-concept around developing a more comprehensive default management area.
For the purposes of this tutorial, we will assume your organization has a basic knowledge of the CRM API and can create and install catalog and UI model projects.
Part 1: Create Catalog project
To get started, go to Visual Studio and create a catalog project, for example: “BrightVine.CustomFx.AttributeDefaults.Catalog”
Create Table Spec
The first thing we need to do is create a place to contain default data. In this case, we want to extend the ATTRIBUTECATEGORY table to contain a column to hold default data.
For our proof of concept, the default column on the extension table is just a large nvarchar field. While an attribute’s default could be a number of types - character, integer, guid, boolean, etc – for this overview, it’s expedient to create one column to hold text representations of the defaults, and have the IO processes deal with casting where necessary.
Create Data Form Extension Spec (for Attribute Add and Edit)
Now, create a Data Form Extension to allow a user to create a default value for new attributes. For this demo, we will just create a text value field, which will mean a user will need to be careful when entering defaults that are, for example, a guid code table value, a yes/no value, a data field, etc. Create a new Data Form Extension spec named “AttributeCategoryAdd2.DataFormExt.xml”. Create an extension for Attribute Edit 3. Note that this form should add an extension record if one doesn’t exist.
Create View Data Form Spec
Next, create a View Data Form spec named AttributeCategoryGetDefault.View.xml. This is a custom view form which will return the default and data type for a particular attribute category ID.
Part 2: Create CodeGen Class Library Project
The next step is something I find useful. When creating a custom data form, view, etc, that will be called from code (as this will be), it’s helpful to run a utility called BBMetalWeb, which may be unfamiliar to your organization if your developers have only had basic SDK training.
BBMetalWeb will parse an XML spec, and create a .NET class which can be used as a first class object in code. This means when you’re calling the View form that was just created, you have the nice early-bound .NET “dot” notation for properties, and Intelligence, so coding and step-through debugging are a lot easier.
To do this, first make sure your View Data Form is loaded (use Load Spec in VS “Tools”), then select BBMetalWeb from Tools. You’ll probably be prompted for the location to the web service, as well as the DB name.
Select View Data Forms and then in the Record Type tab, select “Attribute Category”. BBMetalWeb will create a new class in your catalog project. (You may need to toggle “view all files” to see it). The file “AttributeCategoryGetDefaultViewDataForm.codegen.vb” is the one you’re interested in.
We won’t be able to use AttributeCategoryGetDefaultViewDataForm.codegen.vb in the catalog project. The best practice here will be to create a new project - we called it: BrightVine.CustomFx.AttributeDefaults.CodeGen, and the type should be “class library”. You can simply drag the code gen file into your new project, then delete the entire “ViewForms” folder that got created in the catalog. One thing to note is that you’ll need some references added to the Code Gen project.
Part 3: Create UI Model Project
Because we want our default value to be based on an attribute category selection, we need to make it event driven. That means we want to create UI Model code to handle a change event. First, create a CRM UI Model project, which should import most of the necessary references (we’ll look at any additions later).
Next, go back to the Catalog project and add a new CRM data form add-in item. Just as a reminder, a data form add-in is a lightweight for us to extend an existing data form, when all we want to do is customize the CLR side. It’s much simpler on the XML spec side, only containing a reference to the UI Model code.
Name it “ConstituentAttributeAdd.AddIn.xml” and search for “Constituent Attribute Add Form” in the search box and select the result that appears. At this point you’ll have the aforementioned XML spec. Drag this over to your UI Model project and delete it from the catalog.
Within the ConstituentAttributeAdd.AddIn.vb file, we need to add a Initialize method to create an AppFxWebServiceProvider, as well as an event handler to get the default when the attribute category is changed.
Currently the code handles text, code and Boolean values, but adding other types is just a matter of handling them appropriately in the case statement above.
Part 4: Putting it all together
Make sure all your catalog specs are loaded, then build and deploy the UI Model project. At this point you should be able to configure some defaults on Constituent Attribute categories.
From there, go to a Constituent record and create a new attribute of text, code or yes/no, and you should see your default values appear.
If you'd like to learn more, contact us today!