Home Asset Management
Options

Property Notes exists twice in Standard Class

Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
edited November 2023 in Asset Management

I just came across an Error, when I wanted to create a Standard Object via SMlets.

The error is: "Item has already been added. Key in dictionary: 'Notes' Key being added: 'Notes'"

The standard is created still. After some testing and trying to set the Notes value as well, I checked the Standard Class inside the Entity Explorer. There I saw, that the standard class has 2 properties with the same name "Notes". One is from the configitem class, and one is from the Standard class - both have different property Ids and property types as well.


Is it somehow possible to remove that double poperty in a new version? Or will this lead to errors in the DB and/or all Request Offerings, which contain the standard class in it?

Best Answer

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Answer ✓

    Hi Simon,

    Whilst I agree that the class is a mess (Notes x 2 and Standard Notes) it cannot be changed. It is a supported design within SCSM SDK and I think that whilst a bad design, should work fine. The issue with SMLets, I guess, is technically a bug in SMLets.

    You could bypass SMLets for this process and call the SDK directly.

    Add-Type -Path "D:\Program Files\Microsoft System Center\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.Core.dll"
    Add-Type -Path "D:\Program Files\Microsoft System Center\Service Manager\Microsoft.EnterpriseManagement.Common.dll"
    
    
    $emg = New-Object Microsoft.EnterpriseManagement.EnterpriseManagementGroup "localhost"
    $StandardClass = Get-SCSMClass Cireson.AssetManagement.Standard
    
    
    $cemoStandard = New-Object -TypeName "Microsoft.EnterpriseManagement.Common.CreatableEnterpriseManagementObject" -ArgumentList $emg, $StandardClass
    $cemoStandard[$StandardClass, "Id"].Value = (New-Guid)
    $cemoStandard[$null, "DisplayName"].Value = "My Standard"
    $cemoStandard[$StandardClass, "Name"].Value = "My Standard"
    $cemoStandard[$StandardClass, "Notes"].Value = "These are the Notes"
    $cemoStandard[$StandardClass, "StandardNotes"].Value = "These are the Standard Notes"
    
    
    $cemoStandard.Commit()
    

Answers

  • Options
    Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited February 6

    Anyone from Cireson has an Idea what we could do about this? :)

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.

    Hi Simon,

    You are correct that there are two, but it shouldn't be causing any issues in the DB or ROs. As you say, they have different IDs.

    What issues are you getting.

    Geoff

  • Options
    Simon_ZeinhoferSimon_Zeinhofer Customer Ninja IT Monkey ✭✭✭✭
    edited February 8

    Hy @Geoff_Ross ,

    the error occurs whenever we create a new Standard via Powershell: "Item has already been added. Key in dictionary: 'Notes' Key being added: 'Notes'"

    The standard gets created still, but the error is thrown. It doesn't matter if we set the Notes field on creation or not. This is absolutely no problem in normal scripts, but in powershell activities the activity will fail eventually. So what we did is, we just packed the creation inside a try - catch, where the catch part is just empty. This works fine but the downside is, we would not get an error message if it really fails because of something different :/

  • Options
    Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Answer ✓

    Hi Simon,

    Whilst I agree that the class is a mess (Notes x 2 and Standard Notes) it cannot be changed. It is a supported design within SCSM SDK and I think that whilst a bad design, should work fine. The issue with SMLets, I guess, is technically a bug in SMLets.

    You could bypass SMLets for this process and call the SDK directly.

    Add-Type -Path "D:\Program Files\Microsoft System Center\Service Manager\SDK Binaries\Microsoft.EnterpriseManagement.Core.dll"
    Add-Type -Path "D:\Program Files\Microsoft System Center\Service Manager\Microsoft.EnterpriseManagement.Common.dll"
    
    
    $emg = New-Object Microsoft.EnterpriseManagement.EnterpriseManagementGroup "localhost"
    $StandardClass = Get-SCSMClass Cireson.AssetManagement.Standard
    
    
    $cemoStandard = New-Object -TypeName "Microsoft.EnterpriseManagement.Common.CreatableEnterpriseManagementObject" -ArgumentList $emg, $StandardClass
    $cemoStandard[$StandardClass, "Id"].Value = (New-Guid)
    $cemoStandard[$null, "DisplayName"].Value = "My Standard"
    $cemoStandard[$StandardClass, "Name"].Value = "My Standard"
    $cemoStandard[$StandardClass, "Notes"].Value = "These are the Notes"
    $cemoStandard[$StandardClass, "StandardNotes"].Value = "These are the Standard Notes"
    
    
    $cemoStandard.Commit()
    
Sign In or Register to comment.