Autoincrement Property IDs

I’m writing this blog post while sitting in my car in the middle of a huge traffic jam at famous St.Gotthard in Switzerland (2 hours waiting time) Smiley The positive thing is that I have plenty of time to write a new blog post.

A question I get a lot is how to configure autoincrementing of Property IDs. Unfortunately this is not very well documented. In this blog post I will show you how to successfully do it by using a simple Management Pack.

The Management Pack is used for managing cars – this is really just an example, not a MP I use in production. I created a class that has 4 properties:

class: itnetx.class.cars
property 1: carsID (Key)
property 2: carsManufacturer (String)
property 3: carsModel (String)
property 4: carsPlate (String)

image

The most important settings for the property “carsID” are the following:

  • Autoincrement=”true”

This settings makes sure that the value is automatically incremented for every created object of this class.

  • Key=”true”

This setting declares the property as the key property. That means that the property value for all objects of this class must be unique. The value is used for the unique identification of objects.

  • DefaultValue=”{0}”

This setting holds the default value for new objects and is required for autoincrementing to work correctly. Because I would like to automatically increment the carsID, the value must be set to “{0}”. With this setting a unique sequential integer value is assigned to the property. Most of the default classes use a unique ID (key) that also has a prefix (e.g. Incidents use “IR” to form ID values of “something like “IR1234”). This can also be done by using ‘DefaultValue=”Car{0}”’. This would generate IDs like “Car1”, “Car2” etc.

To make sure key properties have a unique value, autoincrementing these values is the way to go. Ah, by the way: I’m still stuck in the traffic jam and made approx 2km (1.3m) in the last 35 minutes. Hope to get home soon to enjoy the weekend Smiley

regards
Marcel

Additional Information by FreemanRu for configuring views (as stated in the comments):

<mux:Column Name=”carsId” DisplayMemberBinding=”{Binding Path=carsId}” Width=”100″ DisplayName=”Header_carsId” Property=”carsId$ReturnValueAsBigInt$” DataType=”s:Int32″ />

This entry was posted in SCSM and tagged , , , , , , . Bookmark the permalink.

15 Responses to Autoincrement Property IDs

  1. freemanru says:

    Some comments.
    First, This would generate IDs like “Car01”, “Car02” etc.. Right will be “Car1, Car2….Car10” and so on (without leading zero).
    Second, for this columns you can use “$ReturnValueAsBigInt$” postfix in column definition of the view. Example:

    In this case columns value will be like this: “Car00000001, Car00000002” and so on, but display value will be as usual: “Car1, Car2”, this helpfull for sorting data.

    • Hey Anton

      You’re correct. I updated the post and changed “Car01, Car02 …” to “Car1, Car2 …”. Ty for the information!

      btw.: I can not read your example. Can you repost it pls?

      regards
      Marcel

  2. Anton, the code is not visible. pls sent it by mail, i will then try to insert it –> zehner at itnetx dot ch. ty.

    Update: The Code sniplet is now part of the post as i cannot add it to the comments (at the very end …) 😦 ty.

  3. Pingback: Make Service Manager Customer-aware – Part 2 | SCSMfaq.ch

  4. Pingback: System Center Service Manager information(blog) overview - System Center Service Manager

  5. João says:

    Greate Post,
    Thanks,

  6. Pingback: System Center Service Manager information(blog) overview … | The People Search System

  7. Pingback: Dynamic Service Manager CMDB with System Center Orchestrator | SCSMfaq.ch

  8. Guido Racamato. says:

    I Marcel! This a kind of MP pack that i need but the thing is that i need is to assign a ID for a CI but this ID has to assigned automatically when when it is created. Example: If i have a computer asset i need a unique Asset tag created automatically even when it come from system center configuration manager. Can i do that? Your posts are awesome. Regards from Argentina.

    • Hey

      I’m sure if I understand your question correctly, but this solution automatically assigns when a new objects is created, nevermind how the object will be created (manually, SC Orchestrator etc.).

      regards
      Marcel

  9. Pingback: SCSM: Using multiple key properties in classes | marcelzehner.ch

  10. Pingback: SCSM: Using multiple key properties in classes - SysManBlog

  11. Pingback: SCSM: Using multiple key properties in classes

  12. Eric says:

    I am deploying my first custom Management Pack within SCSM 2016.
    5 years after this article, the Autoincrement property is not much better documented!
    Setting it as true works for the type string, but NOT for int! If I let DefaultValue=0 for int, it always stays 0 in my code!
    Similar class as car here, with System.ConfigItem as Base and key=true.
    The generated table in SQL gets another GUID as PrimaryKey, and the ID is thus not defined as ‘Identity’ with ‘increment’.
    But the last Id get property incremented, only if string. It is saved somewhere outside the MP and
    Indeed, if I remove my MP completely over the SM Console and re deploy it (from VS VSAE), I get fresh empty data tables, but the new ID set from my MP is the highest previously set +1.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s