Basic Customization > User Interface Customization > Generic UI Customizations > Preference Framework > Preference Macros > Preference Registry > Creating a Preference
  
Creating a Preference
The creation of a preference is done through an XML load file. When creating a preference the following pieces of information need to be determined:
Unique preference name
Visibility: if the preference will appear in the preference manager UI and visible at what contexts: SITE, ORGANIZATION, CONTAINER or USER.
Preference category: The category the new preference will appear under in the Preference Management utility.
Display name: This is the Name column in the Preference Management utility – string in the form <RBINFO>:< RBINFO key>
Description: This is the Description column in the Preference Management utility – string in the form:
<RBINFO>:<RBINFO key>
Long Description: This description is displayed in the Edit Preference UI, gives a more detailed description including the expected values.
string in the form <RBINFO>:<RBINFO key>
Default value
Value header
In the example below, we will create a new preference named /com/mycompany/MyNewPreference along with an associated preference category to appear in the Preference Manager UI.
1. Create a resource bundle for labels used for your new preference. Labels are needed for display name and description of preference category which the new preference will be visible under in Preference Management UI. Labels are also needed for the display name, description and long description of your preference. Create the file mycompanyPreferenceResource.rbInfo in package com.mycompany.pref. In this example, this file would be added to the <Windchill>/src/mycompany/pref directory.
ResourceInfo.class=wt.tools.resource.StringResourceInfo
ResourceInfo.customizable=true
ResourceInfo.deprecated=false

# Preference Category labels
MyNewPreferenceCategory.displayName.value=My Preference Category
MyNewPreferenceCategory.description.value=Preference Category for my
custom preferences.

# Preference Definition labels
MyNewPreference.displayName.value=Display name of preference /com/my
company/
MyNewPreference
MyNewPreference.description.value=Description of preference /com/myc
ompany/
MyNewPreference.
MyNewPreference.longDescription.value=Long description of preference
/com/mycompany/MyNewPreference.
2. Build the resource bundle by executing the following command from a windchill shell:
ResourceBuild com.mycompany.pref.mycompanyPreferenceResource
3. Restart the servlet engine and the MethodServer.
4. Create Preference load file: createMyNewPreference.xml. It will contain a definition for the new preference category and new preference definition.
<?xml version="1.0"?><!DOCTYPE NmLoader SYSTEM "standardX10.dtd">
<NmLoader>

<csvPreferenceCategory handler="wt.preference.LoadPreference.createPref
erenceCategory">
<csvname>CUSTOM_PREFERENCE_CATEGORY</csvname>
<csvparentName></csvparentName>
<csvdisplayName>
com.mycompany.pref.mycompanyPreferenceResource:
MyNewPreferenceCategory.displayName
</csvdisplayName>
<csvdescription>
com.mycompany.pref.mycompanyPreferenceResource:MyNewPreferenceCategory.
description
</csvdescription>
</csvPreferenceCategory>

<csvPreferenceDefinition handler="wt.preference.LoadPreference.createPref
erence
Definition">
<csvname>/com/mycompany/MyNewPreference</csvname>
<csvvisibility>USER</csvvisibility>

<csvcategoryName>CUSTOM_PREFERENCE_CATEGORY</csvcategoryName>

<csvdisplayName>com.mycompany.pref.mycompanyPreferenceResource:MyNew
Preference.displayName
</csvdisplayName>

<csvdescription>com.mycompany.pref.mycompanyPreferenceResource:MyNew
Preference
.description</csvdescription>

<csvlongDescription>com.mycompany.pref.mycompanyPreferenceResource:
MyNewPreference.longDescription</csvlongDescription>
<csvdefaultValue>Default Value</csvdefaultValue>

<csvhandler>com.ptc.windchill.enterprise.preference.handler.
StringPreferenceValue
Handler:4000
</csvhandler>
</csvPreferenceDefinition>

<csvLinkPreferenceClientDefinition handler="wt.preference.LoadPreference.set
ClientDefinitionLink">
<csvname>/com/mycompany/MyNewPreference</csvname>
<csvclientName>WINDCHILL</csvclientName>
</csvLinkPreferenceClientDefinition>

</NmLoader>
5. Load the preference category and preference definition using the following command:
windchill wt.load.LoadFromFile -d <full
path>/createMyNewPreference.xml