Skip to content

Creating a New Property

Adam edited this page Dec 5, 2021 · 3 revisions

While I've previously written about creating a Setting's style Management pack over on the repo's blog here, it is a bit lengthy if all you are looking to do is to introduce just one new property to the MP to consume in the connector's PowerShell. This wiki article will show you how to quickly add a new property to the Management Pack in C#. In the following examples, I'll be using a property that already exists - WorkflowEmailAddress

PLEASE NOTE: Introducing your own property in a production or even development capacity will break your upgrade path for releases here on the GitHub repository. This article is being provided for potential contributors making forks/pull requests

  1. Add a new property to Settings.mpx.
    • The connector leverages multiple data types, so scan through the mpx file if you need something besides a string.
<Property ID="WorkflowEmailAddress"
              Type="string"
              AutoIncrement="false"
              Key="false"
              CaseSensitive="false"
              MaxLength="256"
              MinLength="0"
              Required="false" />
  1. Add a private variable reference to AdminSettingsWizardData.cs
    • First, the initial variable declaration whether it be a string, boolean, managementpack to reference templates, or an IDataItem to use a SCSM Object Picker. Since the connector leverages multiple data types, you can browse through this file to find other like examples.
private String strWorkflowEmailAddress = String.Empty;
private Boolean boolEnableAutodiscover = false;
ManagementPackObjectTemplate defaultIncidentTemplate;
private IDataItem scsmApprovedAnnouncementGroup;
  • Second, the getter/setter method for the private variable you create above also located in AdminSettingsWizardData.cs. Note the pattern here, because the following Public variable is how we'll reference the variable from here on out. This is how the variable is saved, loaded, and binded to a control in the UI. The private variable from above is nested inside.
public String WorkflowEmailAddress
{
    get
    {
        return this.strWorkflowEmailAddress;
    }
    set
    {
        if (this.strWorkflowEmailAddress != value)
        {
            this.strWorkflowEmailAddress = value;
        }
    }
}
  1. Add a control in the UI. Here in the "GeneralSettingsForm.xaml" file, a textbox is declared with several properties such as height, the control's name on the form, a custom regex validation pattern, and finally where the Text in the textbox comes from. In this case, it's bound to the Public Variable from above.
<TextBox Height="25" Margin="10,0,10,10" x:Name="txtWFEmailAddress" Text="{Binding WorkflowEmailAddress, Mode=TwoWay}" Custom:Validation.RegexPattern="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$"/>
  1. Add code to Save the value in AdminSettingsWizardData.cs in the public override void AcceptChanges(WizardMode wizardMode) method. You can put the code anywhere you want in here, but I've tried to keep them in order based on the order of the panes in the UI. In this example, the value from the textbox is saved to the MP
emoAdminSetting[smletsExchangeConnectorSettingsClass, "WorkflowEmailAddress"].Value = this.WorkflowEmailAddress;
  1. Add code to Load the value in AdminSettingsWizardData.cs in the internal AdminSettingWizardData(EnterpriseManagementObject emoAdminSetting) method.
this.WorkflowEmailAddress = emoAdminSetting[smletsExchangeConnectorSettingsClass, "WorkflowEmailAddress"].ToString();

That't it! A new property has been introduced to the SMLets.Exchange.Connector.AdminSettings class. It Saves and Loads in the UI. Which means you're now free to call the property in the PowerShell through the $smexcoSettingsMP variable. In the case of the workflow email address it's as simple as

$smexcoSettingsMP = ((Get-SCSMObject -Class (Get-SCSMClass -Name "SMLets.Exchange.Connector.AdminSettings$")))
$smexcoSettingsMP.WorkflowEmailAddress

Interested in a deployed, practical example of this? Check out the following Pull Request that executes the above steps to introduce a checkbox on a page (Wizard Step).

Need to add a whole new page (Wizard Step)? Make sure to include it in the SMLetsExchangeConnectorSettingsUI.csproj file as seen on this Pull Request