Updating objects - SmartPlant Foundation - IM Update 44 - Customization & Programming - Hexagon

SmartPlant Foundation Customization

Language
English
Product
SmartPlant Foundation
Search by Category
Customization & Programming
SmartPlant Foundation / SDx Version
10

Unlike creates, which simply occur within the current create configuration, updates have implications on configuration management. The object being updated may not be in the current create configuration. For this reason, we may need to claim the object before changing it.

In the SPF.Server.Utilities namespace, there is a class named SchemaUtilities that has the following method:

Public Shared Function BeginUpdateWithImplicitClaim(ByVal pobjIObject As IObject) As IObject

This should be called before any update. On IObject, you will find this method:

Sub FinishUpdate()

You will find two versions of BeginUpdate on IObject, but these should not be used to ensure that your code will work properly with configuration management.

The actual update of an object simply involves setting the property values on the object. An example is as follows:

Dim lobjHostISPFHost As ISPFHost = CType(SchemaUtilities.BeginUpdateWithImplicitClaim(lobjHostIObject).ToInterface("ISPFHost"), ISPFHost)

lobjHostISPFHost.Description = "changed description"

lobjHostISPFHost.SPFAdminOwner = "updateuser"

lobjHostISPFHost.SPFIsSecure = True

lobjHostISPFHost.FinishUpdate()

Notice that the first statement combines both the BeginUpdateWithImplicitClaim and the ToInterface methods. You can, of course, separate those out to make your code more readable and robust. The next three statements simply change some of the properties on the object. Finally, FinishUpdate is called. However, the changes will not be written to the database until the transaction is committed.