Posted by on May 4, 2017

This post is a reflection on a unique use case from work that combines metadata from a business process with metadata from third-part system, Microsoft System Center Configuration Manager (SCCM), on a K2 SmartForm — how to display SCCM console folders on a K2 SmartForm using the tree control.

Use Case

Display the SCCM console folder location of a given SCCM object (collection, package, or application) in a hierarchical format on a K2 SmartForm. This assumes you have a custom front-end built with K2 SmartForms to consume ancillary business metadata related to SCCM objects, but one could further customize my implementation for other purposes.

Sample tree control showing folder parent-child structure (with some names redacted)

Environment Prerequisites

  • K2 Blackpearl 4.6.11 (or higher)
  • Microsoft SCCM 1607 (or higher)
  • K2 SQL Server Service Broker instance connected to the target SCCM database
  • K2 SmartObject based on SCCM view dbo.vSMS_Folders
  • K2 SmartForms Control Pack (this is now included in 4.7+)

Implementation

vSMS_Folders view from a SQL service instance connected to an SCCM database

You can use the K2 SmartForm tree control to display objects that have a parent-child relationship. In our use case, SCCM console folders each have a ContainerNodeId and a ParentContainerNodeId, surfaced by the SQL view vSMS_Folders.

Folders at the root level have a ParentContainerNodeId of 0 (zero). If you configure the tree control to organize the folders using this parent node relationship, the end result will be a list of folders that you can expand to see their children. When configured for single selection, the tree control will function as a folder selector.

Configure the Tree Control

Create an item view using the K2 Designer (or use an existing view). Add a tree control to the view and configure its data source properties. Set the data source type to SmartObject…

Tree control properties: data source

… and edit the properties to select your SmartObject that is linked to dbo.vSMS_Folders. If you want to show the friendly name of the folder (as it would appear in the SCCM console itself), select the Name value for Display. The ID and Value selections will depend on your implementation, and how you plan to load/save the folder information (if at all). In my example, I am using the ContainerNodeID as my ID and the folder display name (Name) as the Value.

In my example, I am using the SmartObject SCCM.Folder, which has a method called GetFolder. This list method returns all of the folders from the target SCCM site, which can be a problem depending on the size of your site and total number of folders. If you edit the method properties (click the … to the right of the method selector drop-down), you can pass input values to the list method. The most direct approach to narrowing the return set is to specify the object type (ObjectTypeName), and only return folders of that type. In this example, I am specifying only SMS_Package folders:

Editing the SmartObject method input mappings

Quirk: Adding the input mapping here for ObjectTypeName can introduce an odd rule duplication issue with SmartForms 4.6.11. After you add the mapping initially and save it, any future edit could trigger the infuriating issue described in this K2 community article.

Violation of PRIMARY KEY constraint […]. Cannot insert duplicate key in object ‘dbo.@ActionInstance’. The duplicate key value is […]. The data for table-valued parameter “@ActionInstance” doesn’t conform to the table type of the parameter. SQL Server error is: 3602, state: 30 The statement has been terminated.

Resolution:
The Tree view control was creating a second rule each time we tried to save the changes to the view. After deleting rules associated to Tree view control and re-creating it, the issue went away.

Posted in: k2, SCCM, Technical

Comments

Be the first to comment.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: