Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.
How to add list enumeration values programatically in SCSM

Answered How to add list enumeration values programatically in SCSM

  • Saturday, May 21, 2011 6:11 PM
     
     

    How we can add additional list items to existing list enumeration programatically.

    For instance, i have to add one more item to "INCIDENT CLASSIFICATION ENUM"

    Please help me.

    SK

     

All Replies

  • Saturday, May 21, 2011 8:26 PM
    Moderator
     
     
    One option might be using the SCSM PowerShell Cmdlets for this (Add-SCSMEnumeration).
    Andreas Baumgarten | H&D International Group
  • Sunday, May 22, 2011 6:56 AM
    Moderator
     
     

    Hey

    You could use the EnumCreator. See travis blog post --> http://blogs.technet.com/b/servicemanager/archive/2010/02/10/create-list-items-in-bulk-using-enumcreator-xlsx.aspx.

    regards
    Marcel


    SCSMfaq - http://blog.scsmfaq.ch ##### Microsoft Virtualization and Systems Management Partner - http://www.itnetx.ch
  • Sunday, May 22, 2011 6:49 PM
     
     

    Thanks for the answers/ideas.

    Actually i am looking for a C# program to create the new enums. As per the Andreas guided i am looking at the SCSM Powershell Cmdlets source code to find out code to create enums. Please let me know if you see any C# code to create enums.

     

    Thank you.


    SK
  • Sunday, May 22, 2011 11:41 PM
    Moderator
     
     Answered Has Code
    void CreateNewEnum(string ParentEnumName, string mpName, string mpKeyToken, Version mpVersion)
    {
    	EnterpriseManagementGroup gr = new EnterpriseManagementGroup("localhost");
    
    	ManagementPackEnumeration parentEnum = null;
    	ManagementPack mp = gr.GetManagementPack(mpName, mpKeyToken, mpVersion);
    
    	foreach (ManagementPackEnumeration curEnum in gr.EntityTypes.GetEnumerations())
    	{
    		if (curEnum.Name == ParentEnumName)
    		{
    			parentEnum = curEnum;
    			break;
    		}
    	}
    
    	if (parentEnum != null && mp = null)
    	{
    		ManagementPackEnumeration newEnum = new ManagementPackEnumeration(mp, "Enum_" + Guid.NewGuid().ToString("D"), ManagementPackAccessibility.Public);
    		newEnum.Parent = parentEnum ;
    		newEnum.DisplayName = "New enum";
    		newEnum.Description = "New enum from c#";
    		mp.AcceptChanges();
    	}
    }
    
    CreateNewEnum("ChangeStatusEnum", "My.Notsealed.Mp", "", new Version("1.0.0.0"));
    

    http://opsmgr.ru
    • Marked As Answer by kadiyam Monday, May 23, 2011 2:34 AM
    •  
  • Monday, May 23, 2011 2:34 AM
     
      Has Code

    Anton, 

    Thank you very much, your code worked with a small change in my system.

    I am getting below exception if i run the above code,

    XSD verification failed for the management pack. [Line: 0, Position: 0]

    if i changed the

    Guid.NewGuid().ToString("D")
    

    to

    Guid.NewGuid().ToString("D").Replace("-","")
    

    Thank you very much.

    SK


    SK
  • Wednesday, June 13, 2012 11:28 AM
     
     

    Hi Anton ,

    When I am trying to programatically enter value for some of the values it does saves the value in the list , but for some of them error encounters and it displays the following message.Once error is encounted it does not accept any more values.

    || with message: XSD verification failed for the management pack. [Line: 0, gt; System.Xml.Schema.XmlSchemaException: The value 'AMER.Americas CTO Org' is invalid according to its datatype 'ManagementPackUniqueIdentifier' - The Pattern constraint failed. ---> System.Xml.Schema.XmlSchemaException: The Pattern constraint failed. --- End of inner exception stack trace --- at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity) at System.Xml.Schema.XmlSchemaValidator.CheckAttributeValue(Object value, SchemaAttDef attdef) at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String lName, String ns, XmlValueGetter attributeValueGetter, String attributeStringValue, XmlSchemaInfo schemaInfo) at System.Xml.XsdValidatingReader.ValidateAttributes() at System.Xml.XsdValidatingReader.ProcessElementEvent() at System.Xml.XsdValidatingReader.Read() at Microsoft.EnterpriseManagement.Configuration.XSDVerification.ValidateManagementPack(TextReader mpcontents, ManagementPack mp, Boolean throwError) -------------------------------------------------------

    Thanks,S

    Siddhesh.


  • Thursday, June 21, 2012 8:36 AM
     
     

    Hi Anton,

    As in the code mentioned above :

    newEnum.Parent = parentEnum ;
    newEnum.DisplayName = "New enum";
    newEnum.Description = "New enum from c#";
    mp.AcceptChanges();

    DisplayName value is with space.When I try to enter value for Display Name with space , hypen or ampersand it gives me an error in the code.

    But , when the values with space , hyphen or ampersand is added from UI it is accepted as List Value.

    What changes needs to be done so as to add values from the code which needs to be displayed on UI list with spaces or any special character.

    Thanks,

    Siddhesh.


  • Thursday, June 21, 2012 9:14 AM
     
     

    I got the solution !!! :

    Replace the special character in EnumTypeName of EnumType.

    The Display names stays as it is with special character.

    (select * from EnumType where EnumTypeName)

    ManagementPackEnumeration newEnum2 = new ManagementPackEnumeration(mp, strParentName + '.' + strChild.ToString().Trim().Replace(" ", "").Replace("-", "_").Replace("&", "and"), ManagementPackAccessibility.Public);
    newEnum2.Parent = parentEnum;
    newEnum2.DisplayName = strChild;
    newEnum2.Description = strParentName + '.' + strChild;
    mp.AcceptChanges();

    Thanks,

    Siddhesh.Bondre.