Is it possible to get the Template from which a CR was created?

Stefan Horz 3,466 Reputation points
2021-09-29T14:28:49.167+00:00

Hi community, hi @Andreas Baumgarten :-),

is it possible to get the Template from which this CR was created?

136356-cr-from-which-template.jpg

I have a customer with many templates. We are not sure which templates would be used anymore. So we want to create a script to show which templates are used from the Work Items for example in this year.

The Template ID is mostly not filled like in my test environment. Get-SCSMRelatedObject shows no Relation to a template.

Is there any chance to get the template from which a CR was created?

Bets regards,
Stefan

Service Manager
Service Manager
A family of System Center products for managing incidents and problems.
232 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 108.8K Reputation points MVP
    2021-09-29T20:25:53.45+00:00

    Hi @Stefan Horz ,

    the TemplateID of a CR is just a string in the CR property.
    You can write whatever string in the property of any CR.
    If you create a CR based on a template in SCSM console the property TemplateID of the CR will be set with the TemplateID value defined in the CR Template you selected if you click Apply or OK.
    CR35 is created via SCSM console? If so please check the value of the property TemplateID in the CR template you choosed (Template tab if you open the CR template).

    But anyway: If a CR doesn't have a TemplateID you can't find the related CR template. The property is written during CR creation.
    We can follow up on Friday afternoon by phone or Teams if you like ;-)

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


2 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 108.8K Reputation points MVP
    2021-09-29T15:26:28.647+00:00

    Hi @Stefan Horz ,

    the TemplateID of a CR is a property of the CR class.

    136365-image.png

    There is no "CR template class" in SCSM, means "no relationship between CR and template".

    If the Change Request is created via SCSM console the property TemplateID is set by the selected template.
    If the Change Request is created by SCORCH and the TemplateID is not set within the a Create Object activity the property is empty.

    136346-image.png

    This script will get the TemplateID property of a CR (if the property TemplateID is empty no chance to get the CR template, sorry):

    Import-Module SMLets  
    $crID = "CR2136"  
    $classCR = Get-SCSMClass -Name System.WorkItem.ChangeRequest$  
    $crObj = Get-SCSMObject -Class $classCR -Filter "ID -eq $crID"  
    $crObj.TemplateId  
      
    #Output:  
    MajorChangeRequest  
    

    136382-image.png

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  2. Stefan Horz 3,466 Reputation points
    2021-09-29T20:12:51.083+00:00

    Hi @Andreas Baumgarten ,

    thank you. You can see in the screen shot in my inital question the "Template ID" is empty. I fill a "Template ID" in the template of the source but the Work Item which already exists from the template has still no TemplateID.

    PS C:\Users\admstefan.SHOLUTIONS> $CR = Get-SCSMObject -class (Get-SCSMClass -Name 'System.WorkItem.ChangeRequest$') -Filter "ID -eq CR35"  
    $CR.Id  
    $CR.TemplateId  
    CR35  
      
    PS C:\Users\admstefan.SHOLUTIONS>   
    

    Of course newly created Work Items will show the Template ID.

    So perhaps the only chance is to all Templates an ID and then wait some time period for the results?

    Best regards,
    Stefan

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.