Tuesday, March 30, 2010

Type Specs and Predefaults

There are many times when you need to constrain an applet by type. I will explain a declarative technique for doing so in three general situations. In all of these cases, we want to constrain the applet to only show records of a particular type and we want new records to predefault to that type.

Single Valued - Pick Applet: Lets say you have two different type of contacts, 'X Type' and 'Y Type'. I want to be able to pick the 'X Type' contact for an account and the 'Y Type' contact for an account into two different account fields (one for each). I will need to create two new pick lists:

Name: PickList X Type Contact
Business Component: Contact
Long List: Y
Bounded: Y
Type Field: Type
Type Value: X Type

Name: PickList Y Type Contact
Business Component: Contact
Long List: Y
Bounded: Y
Type Field: Type
Type Value: Y Type

On the Account, for the field 'X Contact' set the picklist to 'PickList X Type Contact', set the pick map appropriately, expose a contact pick applet on the account field, etc., and do the same for the account field 'Y Contact'. When the pick applet opens, it will only show Contacts with the respective type field and new contacts created within this pick applet will have there type predefaulted. This is the only way you can declaratively get a predefault of different types. Picklist objects are very "thin" so having a lot of them with different type specs or search specs does not really result in a lot of maintenance overhead. You can even use the same pick applet for both fields.

Multi Valued - MVG/Associate Applet: When the Contacts you wish to add to your hypothetical account are multi valued instead of single valued, a pick list will not help you. Instead you need to use the Type Field/Value on the Multi Value Link. So on the Account, let say you have a Contact MV Link called 'Z Contacts'. Set the properties thus:

Type Field: Type
Type Value: Z Type

This will predefault new contact created within the Associate applet to 'Z Type'. You will also need to add a Search Spec to the Associate applet to constrain the records to 'Z Type'. It is important to do both in this scenario as the MV Link Type spec alone will not update the type of existing records.

Standard List/Form Applet: When constraining and predefaulting a value on a regular applet as opposed to a popup applet, you need to leverage Aspect user properties. These were new properties documented after 7.7 I think and bookshelf does a decent job of documenting them. Basically you need to do the following for each applet representing each different type respectively:
  • Applet class is either CSSFrameListBase or CSSFrameBase
  • Create an Applet User Property:
    Name: Default Aspect
    Value: X Type
  • Create a Field user property on the Contact BC, Type field:
    Name: Aspect Default Value: X Type
    Value: X Type
The Default Aspect property value must match the Field Aspect Default Value expression after the colon (in this case X Type). This confiuration will predefault new records to be a particular type but will not constrain the records that appear. If you need to constrain the records as well, you can add a standard search spec either to the applet or if it is a child applet, to the link.

No comments:

Post a Comment