Accessing attached files of closed Change Requests

Due to a bug in Service Manager, it is no more possible to access attached files once a Change Request has been closed. The only thing you can do to get access to the files is changing the status of the Change Request back from “closed” to “completed”. Because this is not a very ITIL-friendly task, the GUI does not let you change the status once it is set to “closed”. Based on a customer request, I created a small, simple, quick-and-dirty GUI-based script. Because this could be helpful, I share it to the community. Feel free to optimize it Smiley

The script is based on the SMlets. Make sure you have them installed on the computer where you start the script. Also make sure that you have the appropriate permissions in Service Manager.

image

Now enter the Change Request ID and hit the button. In case of a wrong input a warning message is displayed.

image

image

Here we go with the script. It may look very complex, but as you can see I created most of the code with SAPIEN PrimalForms Community Edition. My code is only a few lines.

#Generated Form Function

function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.9.0
# Generated On: 20.04.2011 14:41
# Generated By: itnetx/Marcel Zehner
########################################################################
#region Import the Assemblies
[reflection.assembly]::loadwithpartialname(“System.Windows.Forms”) | Out-Null
[reflection.assembly]::loadwithpartialname(“System.Drawing”) | Out-Null
#endregion
#region Import smlets module
If (( Get-Module -Name smlets -ErrorAction silentlyContinue) -eq $null)
{Import-Module smlets}
#endregion Import smlets module
#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$textBox1 = New-Object System.Windows.Forms.TextBox
$button1 = New-Object System.Windows.Forms.Button
$label1 = New-Object System.Windows.Forms.Label
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects
#———————————————-
#Generated Event Script Blocks
#———————————————-
#Provide Custom Code for events specified in PrimalForms.
$handler_textBox1_TextChanged=
{
}
$handler_button1_Click=
{
Clear-Host
Write-Host “”
Write-Host -foregroundcolor yellow “Processing … please wait”
try
        {
        $crid = $textbox1.text
        $class = get-scsmclass System.WorkItem.ChangeRequest$
        $obj = Get-scsmobject -class $class | where{$_.id -eq “$crid”}

       

        if($obj.status.tostring() -eq “closed”)
            {
            $obj | set-scsmobject -property status -value completed
            $Result = get-scsmobject -class $class | where{$_.id -eq “$crid”} | select displayname,status
            Write-Host “”
            Write-Host -foregroundcolor yellow “Done! You can now close this window …”

           

            }
            else
            {
            Write-Host “”
            Write-Host -foregroundcolor yellow “Selected CR is not closed or does not exist, please check your entry …”
            }
        }

       

catch
        {
        $Result = $Error[0]
        Write-Host “”
        Write-Host “Error in script … aborting.”
        Write-Host “”
        Write-Host $Result
        }

       

}
$OnLoadForm_StateCorrection=
{#Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
}
#———————————————-
#region Generated Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 110
$System_Drawing_Size.Width = 340
$form1.ClientSize = $System_Drawing_Size
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$form1.Name = “form1”
$form1.Text = “Reactivate closed Change Requests”
$textBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 46
$System_Drawing_Point.Y = 24
$textBox1.Location = $System_Drawing_Point
$textBox1.Name = “textBox1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 20
$System_Drawing_Size.Width = 126
$textBox1.Size = $System_Drawing_Size
$textBox1.TabIndex = 2
$textBox1.Text = “CR”
$textBox1.add_TextChanged($handler_textBox1_TextChanged)
$form1.Controls.Add($textBox1)
$button1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 199
$System_Drawing_Point.Y = 17
$button1.Location = $System_Drawing_Point
$button1.Name = “button1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 32
$System_Drawing_Size.Width = 89
$button1.Size = $System_Drawing_Size
$button1.TabIndex = 1
$button1.Text = “un-close CR!”
$button1.UseVisualStyleBackColor = $True
$button1.add_Click($handler_button1_Click)
$form1.Controls.Add($button1)
$label1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 88
$System_Drawing_Point.Y = 64
$label1.Location = $System_Drawing_Point
$label1.Name = “label1”
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 16
$System_Drawing_Size.Width = 155
$label1.Size = $System_Drawing_Size
$label1.TabIndex = 0
$label1.Text = “(c) 2011 by itnetx gmbh/ZE”
$form1.Controls.Add($label1)
#endregion Generated Form Code
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$form1.ShowDialog()| Out-Null
} #End Function
#Call the Function
GenerateForm

That’s it. As I said, very small, simple and easy … but effective and most of the time you won’t need more. I’m waiting for your feedback and of course your optimizations!

regards
Marcel

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

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