Customizing Operator Advisor > Extending the Operator Advisor Data Model > Adding Custom Properties to Operator Advisor Entities
Adding Custom Properties to Operator Advisor Entities
Most entities in the Operator Advisor data model have a related _AP Data Shape for the purpose of adding custom properties. For example, the job order Data Shape (PTC.SCA.SCO.JobOrder) has an associated PTC.SCA.SCO.JobOrder_AP Data Shape. The example in this topic adds a new Location property to the PTC.SCA.SCO.JobOrder_AP Data Shape.
Adding custom properties to Operator Advisor involves multiple steps:
For an example showing how to programmatically populate the new custom property using a service, see Populating a Custom Property.
Add Field to the Data Shape
1. In ThingWorx Composer, navigate to the _AP Data Shape for the entity. For this example, navigate to PTC.SCA.SCO.JobOrder_AP.
2. Under Field Definitions, click Add.
3. On the New Field Definition pane, specify the following:
Name—The name for the property. For this example, enter Location.
Base Type—The data type for the property. For this example, select STRING.
4. Click Check mark icon to add the new field definition.
5. Click Save to save the updates to the Data Shape.
Update the Database Information with any Database Constraints
If your new property requires any database constraints, complete the following steps:
1. Navigate to the PTC.SCA.SCO.DefaultProductionOrderManager Thing.
2. Under Services, find and override the Get<entity>DBInfo service for the entity to which you are adding the property. For this example, find and override the GetJobOrderDBInfo service.
3. In the script editor, scroll down to the entry for the Data Shape to which you added the property. In this example, look for the following entry:
"dataShapeName": "PTC.SCA.SCO.JobOrder_AP",
"indexedFields": []
4. Update the entry for the Data Shape with the database information for the new property.
If the property is to be indexed, add it to the indexedFields array for the Data Shape, with the following properties:
name—(Required) Name of the property.
unique—Specify if the property must have a unique value.
identifier—The name of the entity in the database. If not specified, then the system automatically generates the value in the format <table_name>_<column_name>_idx. If specified, then the value must be unique for both specified values and any automatically generated values. The maximum length for the value is the maximum length allowed by the database for identifiers.
If the property is to be a foreign key, add a foreignKeys array for the Data Shape, with the following properties:
name—Name of the property on the current Data Shape to be a foreign key.
referenceDataShapeName—The Data Shape of the referenced database table.
referenceFieldName—The name of the field containing the value being referenced.
onDelete—What happens, if anything, to instances of the current Data Shape when instances of the referenced Data Shape are deleted.
deleteReference—What happens, if anything, to instances of the referenced Data Shape when instances of the current Data Shape are deleted.
For more information on the delete behaviors, see Setting the Delete Behavior with Foreign Keys.
To specify additional database constraints for the property, add it as an entry in a fields array:
name—The name of the new property. Required.
length—Column length for the new property, if different than the default column length for the database.
notNull—Specify if the property must not be null.
* 
If a database column must have a unique value, specify this using unique in the indexedFields array, rather than in the fields array.
For this example, to specify that Location has a column length of 4000 characters and cannot have a null value, update the entry for the PTC.SCA.SCO.JobOrder_AP Data Shape as follows:
{
"dataShapeName": "PTC.SCA.SCO.JobOrder_AP",
"indexedFields": []
"fields": [{
"name": "Location",
"length": 4000
"notNull": true
}]
},
5. Click Save to save the changes to the service.
Synchronize the Database Information and Database Schema
Synchronize the database information with the database schema. For more information, see Synchronizing the Database Information and the Database Schema.
Populating a Custom Property
The following code is an example of how to include the custom property in a service to programmatically populate the property. This code uses the CreateInfoTable service to merge the PTC.SCA.SCO.JobOrder and PTC.SCA.SCO.JobOrder_AP Data Shapes into a single infotable, and populates the new Location property with the value of Montreal.
var jobOrderDataShapeName = "PTC.SCA.SCO.JobOrder";
var productionManagerThingName = Things["PTC.Factory.LaunchPointConfigurationThing"].GetProductionOrderManagerThingName();
var jobOrders = Things[productionManagerThingName ].CreateInfoTable({
dataShapeName: jobOrderDataShapeName
});

var jobOrder = {};
jobOrder.ID = "" + 121;
jobOrder.WorkType = 1;
jobOrder.Description = "test";
jobOrder.Location = "Montreal";
jobOrders.AddRow(jobOrder);

var newJobOrders = Things[productionManagerThingName ].CreateJobOrders({
JobOrders: jobOrders
});
Was this helpful?