Home General Discussion

How can I get the template GUID or name that is applied to a request offering?

German_IslasGerman_Islas Customer IT Monkey ✭
Hello,

I am trying to get the template name or guid that is assigned to a request offering through PowerShell.
Any suggestions as to how I can go about this?
Thank you.

Here is what I have so far.

$SRnumber = "SR1234"

$SRClass = Get-SCSMClass -name "System.WorkItem.ServiceRequest$"
$requestOfferingClass = Get-SCSMClass -Name "System.RequestOffering$"
$WorkitemRelatesToRequestOffering = Get-SCSMRelationshipClass -name "System.WorkitemRelatesToRequestOffering$"

$SRObject = Get-SCSMObject -Class $SRClass -Filter "name -eq $SRnumber"
$requestOffiring = (Get-SCSMRelationshipObject -BySource $SRObject | Where-Object {$_.RelationshipID -eq $WorkitemRelatesToRequestOffering.id}).TargetObject


Best Answer

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓
    This might be the long way around, but it works for me:

    $template = $requestOffiring.Values | ?{$_.type -like '*targettemplate*'} | select -expandproperty value
    $templateName = $template.Split("|")[3]
    $templateObject = Get-SCSMObjectTemplate -Name $templateName
    $templateObject

Answers

  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    edited January 2019
    You were very close!
    (Get-SCSMRelationshipObject -BySource $SRObject | Where-Object {$_.RelationshipID -eq $($WorkitemRelatesToRequestOffering.id) }).sourceobject

    You have to wrap $WorkitemRelatesToRequestOfffering.id in $() to capture the actual value.
  • German_IslasGerman_Islas Customer IT Monkey ✭
    Oops, it looks like placed the wrong code for the request offering. Thank you for correcting that. Would you happen to know how  I can get the template that is assigned to the request offering?
  • Justin_WorkmanJustin_Workman Cireson Support Super IT Monkey ✭✭✭✭✭
    Answer ✓
    This might be the long way around, but it works for me:

    $template = $requestOffiring.Values | ?{$_.type -like '*targettemplate*'} | select -expandproperty value
    $templateName = $template.Split("|")[3]
    $templateObject = Get-SCSMObjectTemplate -Name $templateName
    $templateObject
  • German_IslasGerman_Islas Customer IT Monkey ✭
    Thank you, that worked.
Sign In or Register to comment.