Sep
25

Part 1: Custom Form Templates for Service Manager 2012

By

A while back I created some “custom form templates” to be used with the Service Manager Authoring Tool (2010). The purpose was to enable “authors” to re-use some of the existing controls in Service Manager like the “Related Items Tab” and the “History Tab” when creating new forms in the Authoring Tool. By request I’ve updated these to support Service Manager 2012. So far I’ve just added two templates that contain the “Related Items Tab” and the “History Tab”. One template is for Work Items and one is for Configuration Items.

SNAGHTMLc125cb

If you just want to try the templates out you can go ahead and download this example bundle: Litware.SCSM.FormsExample.mpb. After importing it you can use any of the following two views to try out the forms using the Create MyWorkItem or Create MyConfigItem task:

  • Work Items > My Work Items > All My Work Items
  • Configuration Items > My Config Items > All My Config Items

To learn how to use the custom templates in the Service Manager Authoring Tool let’s create two simple classes and a form for each of them (based on the templates).

Creating the Example Manangement Pack

  1. Create a folder called C:\Temp\MyCustomForms
  2. Copy Litware.SCSM.CustomFormTemplates.dll to C:\Temp\MyCustomForms
  3. Start the Service Manager Authoring Tool
  4. Create a new Management Pack called “Litware.SCSM.FormsExample.xml” in “C:\Temp\MyCustomForms

Creating a custom Configuration Item class

  1. Right click Classes and select “Create Configuration Item Class…
    image
  2. In the Create Class dialog, name the class “MyConfigItem” and click Create.
  3. Add a new property by clicking “Create Property…”, name the property “PrincipalName”.
  4. While having the new property selected, mark it as Key in the Details pane.
    image
  5. Delete the property that was automatically added (called something like Property_…) when you created the class.
    image
  6. In the confirmation dialog, click yes to delete the property.

Creating a custom Work Item class

  1. Right click Classes and select “Create Work Item Class…
  2. In the Create Class dialog, name the class “MyWorkItem” and click Create.
  3. Delete the property that was automatically added (called something like Property_…) when you created the class.

We don’t have to add a new key property to the custom Work Item class since we’re already inheriting a key property.

Using the Configuration Item Form Template

  1. Right click Forms in the Management Pack explorer, select Add Custom
    image
  2. In the Base Class dialog, select your custom class called MyConfigItem and click OK
  3. In the Add custom fom dialog, name your form MyConfigItemForm, select the following assembly C:\Temp\MyCustomForms\Litware.SCSM.CustomFormTemplates.dll
  4. Still in the Add custom form dialog, in the type selection drop down select CITemplate (which contains both a related items and the history tab) and click Create
    SNAGHTML74e66a
  5. In the the “Form Designer”, add a Label and a TextBox to General tab.
  6. Change the Content of the Label to “Principal Name”
  7. Change the Binding Path of the TextBox to PrincipalName
    image

Using the Work Item Form Template

  1. Right click Forms in the Management Pack explorer, select Add Custom
  2. In the Base Class dialog, select your custom class called MyWorkItem and click OK
  3. In the Add custom fom dialog, name your form MyWorkItemForm, select the following assembly C:\Temp\MyCustomForms\Litware.SCSM.CustomFormTemplates.dll
  4. Still in the Add custom form dialog, in the type selection drop down select WITemplate (which contains both a related items and the history tab) and click Create
  5. In the the “Form Designer”, add a Label and a TextBox to General tab.
  6. Change the Content of the Label to “Title”
  7. Change the Binding Path of the TextBox to Title
  8. Save all changes and exit the Service Manager Authoring Tool

Wiring up a working binding source

Since the control used for the Related Items tab requires a type projection with specific components to work, let’s go through the steps required to make sure we provide that.

  1. Open up C:\Temp\MyCustomForms\Litware.SCSM.FormsExample.xml in an XML editor
  2. In the <References> section, make sure you have the following references:

    <Reference Alias="WorkItem">
            <ID>System.WorkItem.Library</ID>
            <Version>7.5.1561.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> 
    </Reference> 
    <Reference Alias="SupportingItem">
            <ID>System.SupportingItem.Library</ID>
            <Version>7.5.1561.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> 
    </Reference> 
    <Reference Alias="CoreKnowledge">
            <ID>System.Knowledge.Library</ID>
            <Version>7.5.1561.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> 
    </Reference> 
    <Reference Alias="ConfigurationManagement">
            <ID>ServiceManager.ConfigurationManagement.Library</ID>
            <Version>7.5.1561.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken> 
    </Reference>

    Note: If you already have references to any of these Management Packs, make sure the alias of the existing reference matches the alias in the XML above.

  3. In the <EntityTypes> section (below the <ClassTypes> section) add the following two type projections encapsulated in the <TypeProjections> tag
  4. <TypeProjections>
            <TypeProjection ID="MyConfigItem.Projection" Accessibility="Public" Type="MyConfigItem">
              <Component Path="$Context/Path[Relationship='WorkItem!System.WorkItemRelatesToConfigItem' SeedRole='Target']$" Alias="ImpactedWorkItem" />
              <Component Path="$Context/Path[Relationship='WorkItem!System.WorkItemAboutConfigItem' SeedRole='Target']$" Alias="RelatedWorkItem" />
              <Component Path="$Context/Path[Relationship='SupportingItem!System.ConfigItemHasFileAttachment']$" Alias="FileAttachment" />
              <Component Path="$Context/Path[Relationship='System!System.ConfigItemRelatesToConfigItem']$" Alias="RelatedConfigItem" />
              <Component Path="$Context/Path[Relationship='System!System.ConfigItemRelatesToConfigItem' SeedRole='Target']$" Alias="RelatedConfigItemSource" />
              <Component Path="$Context/Path[Relationship='CoreKnowledge!System.EntityLinksToKnowledgeDocument']$" Alias="RelatedKnowledgeArticles" />
    </TypeProjection>

    <TypeProjection ID="MyWorkItem.Projection" Accessibility="Public" Type="MyWorkItem">
              <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemHasFileAttachment']$" Alias="FileAttachments">
                <Component Path="$Target/Path[Relationship='SupportingItem!System.FileAttachmentAddedByUser']$" Alias="FileAttachmentAddedBy" />
              </Component>
              <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem']$" Alias="RelatedWorkItems">
                <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAffectedUser']$" Alias="RWIAffectedUser" />
                <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RWIAssignedUser" />
              </Component>
              <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemRelatesToWorkItem' SeedRole='Target']$" Alias="RelatedWorkItemSource">
                <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAssignedToUser']$" Alias="RelatedWorkItemAssignedTo" />
              </Component>
              <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAboutConfigItem']$" Alias="RelatedConfigItems" />
              <Component Path="$Target/Path[Relationship='WorkItem!System.WorkItemAboutConfigItem' TypeConstraint='CoreKnowledge!System.Knowledge.Article']$" Alias="RelatedKnowledgeArticles" />
            </TypeProjection>
    </TypeProjections>

  5. Now let’s wire up the forms to each of the type projections. For the Config Item form, find the <Form> with ID="MyConfigItemForm" and replace Target="MyConfigItem" with Target="MyConfigItem.Projection"
  6. For the Work Item form, find the <Form> with ID="MyWorkItemForm" and replace Target="MyWorkItem" with Target="MyWorkItem.Projection"
  7. Save the file and exit the XML editor.

Creating the Management Pack Bundle

Before we’re ready to go we need to create a Management Pack Bundle which contains the Management Pack and the dll that contains the form templates.

  1. Open up a PowerShell command prompt
  2. Execute the following commands:
    import-module smlets
    cd C:\Temp\MyCustomForms
    New-MPBFile.ps1 .\Litware.SCSM.FormsExample.xml .\Litware.SCSM.FormsExample –computername SCSMComputerName

Note: I just loaded up smlets to get access to New-MPBFile.ps1, nothing else. Smlets can be found at http://smlets.codeplex.com

Taking the custom forms for a spin

  1. Import the Management Pack Bundle: Litware.SCSM.FormsExample.mpb
  2. Restart the console
  3. Create views for the custom classes (in the example files available as download in the top of the blog post I’ve already added the views)
  4. Use the console tasks Create MyConfigItem or Create MyWorkItem to try out the forms.

In Part 2 I’ll show you how the templates were created!

Important: Throughout this blog post I’m storing date model resources like managment pack classes in unseald management packs. You should always avoid this in production scenarios but since this is just to demo the templates I didn’t go through the extra steps required. Normally I would have created a separate managment pack with all data model resources within and selad that before starting up the creation of forms.

Comments

  1. Patrick says:

    Hi,

    Helpful post! Thank you!

    I have problems with sealing the MP.

    I have created one MP for the classes and one for the forms.

    Step “Wiring up a working binding source” part 2 and 3 I have done in the “Classes MP”.
    part 4 and 5 I have done in the “Forms MP”

    Sealing and creating the MPB works fine.

    But when I want to import the MPB I get the following Error:

    The management pack import failed.
    Errors (2):
    Form Form_CI_LeaseSchedules has a target that is not valid. The target must be either a simple class or a combination (TypeProjection) class.
    : Cannot find ManagementPackElement [Type=ManagementPackElement, ID=CI_LeaseSchedules.Projection] in management pack ManagementPack:[Name=SR_MP_SM_CI_LeaseSchedules_Forms, KeyToken=, Version=1.0.0.0].

    Form Form_WI_LeaseSchedules has a target that is not valid. The target must be either a simple class or a combination (TypeProjection) class.
    : Cannot find ManagementPackElement [Type=ManagementPackElement, ID=WI_LeaseSchedules.Projection] in management pack ManagementPack:[Name=SR_MP_SM_CI_LeaseSchedules_Forms, KeyToken=, Version=1.0.0.0].

    (I want to create a CI leaseschedules with the ability to add related items…)

    I have tested the unsealed Version with no problems. But when I want to create a view, I get an error that the MP must be sealed…

    Any idea how to solve this? Has anybody tested this with sealing?

    Thanks for every idea!!!

    Best Regards,
    Patrick

  2. German says:

    Hi Patrik,

    This is great! Thanks for putting this together!

    Any idea why the Related Items buttons may be all disabled while creating or editing a new item? (I’m using SCSM 2012)

    Thanks!
    German

  3. Patrik Sundqvist says:

    Hi German,

    You need to make sure your type projection has the required components. Are you using the config item or work item “template”?

  4. German says:

    Hi Patrik,

    This is my class type:

    And this is the form declaration:

    Do you see anything wrong there?

  5. German says:

    Weird… it removed the code… either way… I think the issue is that I based the form on the class an not a type projection as you mentioned.

  6. Amanda says:

    Hi Patrik
    This is great. I am using it in SCSM2012 successfully. The only issue we are having is with the image for the Calendar form control. When we import the MPB into SCSM the icon for calendar to choose does not come it. Just get a box with show calendar text in it.
    When you click on the button it works fine. Any ideas why the image is not working?
    Thanks

  7. John says:

    Hi Patrik,

    How, if possible could i change the mapping of the Activity stage field at the top of the Service request form banner. Its mapping the title of the Activities instead of the Activity stage? Would i need visual studio or something to get into the form to make those kinds of modifications?

    I’m using your templates by the way, making life and reporting so much easier!

  8. Patrik Sundqvist says:

    Hi John,
    This is not as trivial as it might seem. In the Change Request form, where this is already working, this is managed by the “code behind”. In other words, you would have to inject a custom control onto the form that has similar “code behind” to locate the “current activity in progress” (and display the information).

    An alternative would be to extend the service request class with a string property “X” kick of a workflow each time an activity becomes In-Progress and have the workflow find the parent service request and write it’s name to property “X”. Then just customize the form to show the value of property “X”. Also, the workflow would need to discard all non-service request cases.

  9. [...] instructions on how you can build your custom forms using Visual Studio, like this link, this link, and this [...]

  10. Harpreet says:

    Hi I am using the Litware.SCSM.CustomFormTemplates.dll in SCSM 2012. I want to Set the Title bar of my custom forms so that when I import the MP into console and open the form, the title bar should have a “Custom Name” instead of “Form Host”. Please advise.

    Thanks
    Harpreet

  11. Harpreet says:

    Hi, I am still struggling to set the Title bar of my custom forms while using Litware.SCSM.CustomFormTemplates.dll in SCSM 2012. I am still not able to get a “Custom defined name” instead of “Form Host”. Could you please advise if it is possible on the template?

    Regards

Leave a Reply