Home Service Manager

Powershell Creation of SR from Template - Setting Request Offering

David_WellsDavid_Wells Customer Adept IT Monkey ✭✭
Hi Brains Trust,

I've scripted the automatic creation of an SR based on a template using powershell with the help of:
however I am still to work out how to add the Request Offering to the new SR.

Any ideas?

Best Answer

  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    Answer ✓
    Hi David,

    After committing the changes to the properties, you can add this code:

    # commit them
    $TemplateObjects | % {$_ | Set-SCSMObject -PropertyHashtable $PropertyCollection[$_.get_id().Guid] -ComputerName $ComputerName}

    #new code to add Request Offering relationship
    $relClass = Get-SCSMRelationshipClass -Id 2730587f-3d88-a4e4-42d8-08cf94535a6e
    $proj = Get-SCSMTypeProjection System.WorkItem.ServiceRequestPortalProjection
    $SRID = $RequestObject.Id
    $SRRequest = Get-SCSMObjectProjection -Projection $proj -filter "Id -eq $SRID"
    $SRRequest.__base.Add($RequestOffering.Object,$relClass.Target)
    $SRRequest.__base.Commit()

Answers

  • Leigh_KildayLeigh_Kilday Member Ninja IT Monkey ✭✭✭✭
    Perhaps we could attempt this in .Net
  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    Answer ✓
    Hi David,

    After committing the changes to the properties, you can add this code:

    # commit them
    $TemplateObjects | % {$_ | Set-SCSMObject -PropertyHashtable $PropertyCollection[$_.get_id().Guid] -ComputerName $ComputerName}

    #new code to add Request Offering relationship
    $relClass = Get-SCSMRelationshipClass -Id 2730587f-3d88-a4e4-42d8-08cf94535a6e
    $proj = Get-SCSMTypeProjection System.WorkItem.ServiceRequestPortalProjection
    $SRID = $RequestObject.Id
    $SRRequest = Get-SCSMObjectProjection -Projection $proj -filter "Id -eq $SRID"
    $SRRequest.__base.Add($RequestOffering.Object,$relClass.Target)
    $SRRequest.__base.Commit()

  • David_WellsDavid_Wells Customer Adept IT Monkey ✭✭
    Legend!
  • David_WellsDavid_Wells Customer Adept IT Monkey ✭✭
    OK, supplementary question.

    We are now looking to create a template using powershell as a precursor to creating a request off this template (as per above).

    You can create a shell for the template using SMLets: New-SCSMObjectTemplate but I've been unable to find any way of setting / adding the properties and objects within the template given these templates are management pack objects, other than by editing the XML. Actually you can set them by getting the objects property / object collection and setting the properties but how do you save these updates back into the template itself (as opposed to applying the template to another object / projection via Set-SCSMObjectTemplate).

    Has anyone achieved this?
Sign In or Register to comment.