Creating your own forms

In the Creating new classes recipe, we have added a class to Service Manager to store instances of peripheral devices in our CMDB. While the generic form that was used to manage the devices might be sufficient, you are still likely to come into the situation where you want to have control over what controls to display, and the layout of the form.

The Service Manager 2016 form infrastructure not only allows for the existing forms to be customized, but also offers the capability to add new forms.

In this recipe, we will walk you through the steps required to create your custom form using the Authoring Tool.

Getting ready

In addition to having knowledge on how to use the Authoring tool and how you seal management pack, you need to have completed the Creating new classes recipe earlier in this chapter.

You will need a basic understanding of the form infrastructure in Service Manager. It is therefore recommended that you read through the Getting ready section of the previous recipe, Customizing default forms.

How to do it...

We will now use the Authoring Tool to create a new form for the Peripheral Device class that we defined in the Creating new classes recipe earlier in this chapter:

  1. Open the Authoring Tool, go to File, and click New. Give the new management pack the name Packt.PeripheralDevice.Form.xml.
  2. Go to File and click Open. Locate and open the sealed management pack that holds the Peripheral Device class (Packt.PeripheralDevice.Class.mp).
  3. With both management packs opened, right-click Forms under Packt.PeripheralDevice.Form in the Management Pack Explorer, and click on Create.
  4. In the Base class pop-up window, select the Peripheral Device class, and click on OK.

    How to do it...

  5. In the Create form pop-up windows, enter PeripheralDeviceForm as the Internalname, and then click on OK.
  6. You will now see that the form has been added to your management pack, and the form will also be displayed in the Authoring Pane and can now be edited.
  7. Click on the PeripheralDeviceForm form in the Management Pack Explorer. In the Details pane, change the Name property to Peripheral Device Form, and clear the Description property.
  8. Drag and drop a Label control from the Form Customization Toolbox to the form in the Authoring Pane.
  9. Select the newly added Label control, and then, in the Details pane, configure the following properties:
    • Height: 20
    • Horizontal Alignment: Left
    • Minimum Height: 0
    • Minimum Width: 0
    • Vertical Alignment: Top
    • Width: Auto
    • (Margin) Bottom: 0
    • (Margin) Left: 20
    • (Margin) Right: 0
    • (Margin) Top: 20
    • Content: ID:
  10. Now, drag a Text Box control from the Form Customization Toolbox to the form in the Authoring Pane and drop it somewhere on the form. We will configure the margins to get the correct placement in the next step.
  11. Select the newly added Text Box control, and then, in the Details pane, configure the following properties:
    • Binding Path: PeripherialDeviceID
    • Height: 23
    • Horizontal Alignment: Left
    • Minimum Height: 0
    • Minimum Width: 0
    • Vertical Alignment: Top
    • Width: 120
    • (Margin) Bottom: 0
    • (Margin) Left: 20
    • (Margin) Right: 0
    • (Margin) Top: 45
    • Is Enabled: False
  12. We are disabling this particular control because the ID value is defined to be automatically assigned.
  13. Now add labels and controls for the following properties:
    • Device Name
    • Description
    • Device Type
    • Serial Number
    • Asset Tag
  14. Aside from the Is Enabled property (which shouldn't be touched for these controls) use the similar preceding configuration. You will have to play around with the margins to find a layout that fits your need. Don't try to use the mouse to move the controls around as it will write excessive rows of XML in the management pack, but it is also very hard to get exact placement using the mouse.
  15. When adding the DescriptionTextBox it might be a good idea to make it a bit higher than the other controls as it may contain some more text. It might also be a good idea to set the Text Wrapping to Wrap with overflow and Accepts the ENTER key to True for this control.
  16. If you want, you can also add a User Picker control for the Owned By User relationship that is inherited from the System.ConfigItem class to indicate the owner of the device.
  17. When you're finished with the design, save your management pack by using Save all under the File menu. The following screenshot shows how the form design might look:

    How to do it...

  18. Seal the management pack. For more information on how to seal a management pack, please refer to the Sealing Management packs recipe earlier in this chapter.
  19. Open the Service Manager console and navigate to the Management packs view in the Administration workspace.
  20. In the task pane, click on Import, and browse to the location where you stored your sealed management pack. On the lower-right, change MP files(*.xml) to MP files(*.mp), click on the Packt.PeripheralDevice.Form.mp file, click on Open, and then click on Import. When the import process is finished, click on OK.
  21. Go to the Configuration Items workspace, open the All Peripheral Devices view created in the Creating new classes recipe and double-click on any of the listed peripheral devices, or create a new one using the Create Peripheral Device task in the task pane.

From now on, Service Manager will use the newly added form when you work with instances of the Peripheral Device class.

How it works...

With the creation of a custom form for the Peripheral Device class, Service Manager now no longer displays the generic form. By creating your custom form, you have total control over which properties are displayed on the form, over the layout of the controls, and also on the design of the form.

For more advanced forms you can use Visual Studio to create these. Using Visual Studio you can also create your own custom WPF user controls that can be used in your custom forms. Unfortunately, using Visual Studio for advanced customization of Service Manager is out-of-scope for this book.

See also

Refer to the following recipe in this chapter for more information on how to create a custom class for Service Manager:

  • Creating new classes
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset