Customizing Information Content and Access > Creating a Custom Manager
Creating a Custom Manager
The data model uses manager Things to control certain functionality. The manager Thing holds the necessary functions for any database manipulation for the functionality, such as creating and updating database tables. The manager Thing also implements all the Thing Shapes responsible for managing the services related to the associated object model.
These managers are defined in the ManagerConfigurationSettings table on the Configuration page of the launch point configuration Thing (PTC.Factory.C_LaunchPointConfigurationThing_[ReleaseVersion]).
The ManagerConfigurationSettings table from the Configuration page of the launch point configuration Thing.
Default manager Things are provided for each manager out-of-the-box.
You can create custom managers to manage (create and update) your own database tables. Use the default manager Things as models.
The following steps describe how to create a manager that manages a database table named customdata, with two columns: UID (primary key, autogenerated) and CustomProperty1 (string data type). The customdata table is initialized with two rows.
1. In ThingWorx Composer, create a new Data Shape.
a. For Name, enter CustomData.
b. Under Field Definitions, click Add.
c. Define the following field:
Name—Enter UID.
Base Type—Select LONG.
Is Primary Key—Select this checkbox.
d. Click Icon to add the current field and immediately add another field. to add the first field, and define another field:
Name—Enter CustomProperty1.
Base Type—Select STRING.
e. Click Add icon to add the second field.
f. Click Save to save the new Data Shape.
2. In ThingWorx Composer, create a new Thing Template.
a. For Name, enter CustomManagerThingTemplate.
b. For Base Thing Template, select any Thing Template. For example, GenericThing.
c. For Implemented Shapes, search for and add PTC.SCA.SCO.DBManagementThingShape. If the manager is to call create services, search for and add PTC.SCA.SCO.ServiceConfigurationThingShape, as well.
d. Click Save to save the Thing Template.
3. In ThingWorx Composer, create a new Thing.
a. For Name, enter CustomManagerThing.
b. For Base Thing Template, search for and select CustomManagerThingTemplate (the Thing Template created in step 2).
c. Under Services, override the GetDBInfo service and add the following code, then click Done:
var result = {
dbInfo: [{dataShapeName: "CustomData"}]
};
d. Under Services, override the InitData service and add the following code, then click Done:
var infoTable = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName : "InfoTable",
dataShapeName : "CustomData"
});

infoTable.AddRow({"CustomProperty1":"TestValue1"});
infoTable.AddRow({"CustomProperty1":"TestValue2"});

Things[me.GetDatabaseThingName()].Insert({
infoTable: infoTable,
dataShapeName: "CustomData"
});
e. Click Save to save the Thing.
4. Register the custom manager.
a. Navigate to the launch point configuration Thing (PTC.Factory.C_LaunchPointConfigurationThing_[ReleaseVersion]).
b. Under Configuration, click Add for the ManagerConfigurationSettings configuration table.
For Name, enter a name for the custom manager, for example, CustomDataManager.
For Value, search for and select the custom manager Thing created in step 3.
c. Click Add to add the custom manager to the configuration table.
d. Click Save to save the updates to the launch point configuration Thing.
5. On the CustomMangerThing created in step 3, under Services, execute the CreateTables service. A database table named customdata is created containing two rows.
6. If you want to define foreign keys, see Adding or Removing Foreign Keys.
7. To change the length of String database columns, see Setting Length for STRING Database Columns.
8. To configure pre- or post-action event dispatching and validation, see Pre- and Post-Action Event Dispatching and Validation.
Was this helpful?