Home Service Manager

Prompt for a task value

Alex_MarshAlex_Marsh Premier Partner Advanced IT Monkey ✭✭✭
Hi All

This came from a recent thread around purchase order line items and being able to create them from catalog items. What I am currently doing is trying to create a task which will create a line item from a selected catalog item. What I've got stuck with is that I can't work out how to prompt for a value, i.e. number of units. Anyone have any idea on how to do this?

Answers

  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Hi Alex,

    Sounds good. Are you building this in the Console or the Portal?

    Geoff
  • Alex_MarshAlex_Marsh Premier Partner Advanced IT Monkey ✭✭✭
    In the console for the time being. While my powershell skills aren't bad my json is non-existent!
    I've managed to get something working but it relies on a task that calls a powershell script instead of having everything built into the task (didn't work within the task for some reason).
    Here's what I've got so far. The end user gets 2 pop ups asking for the quantity of the selected catalog item and the PO number it's linked to

    param($cat,$cost)
    $props = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\System Center\2010\Common\Setup";
    $instdir = $props.InstallDirectory + "Powershell\System.Center.Service.Manager.psd1";
    $smms = $instdir + $ps; 
    Import-Module $smms;

    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing

    $form = New-Object System.Windows.Forms.Form 
    $form.Text = "Data Entry Form"
    $form.Size = New-Object System.Drawing.Size(300,300) 
    $form.StartPosition = "CenterScreen"

    $OKButton = New-Object System.Windows.Forms.Button
    $OKButton.Location = New-Object System.Drawing.Point(75,120)
    $OKButton.Size = New-Object System.Drawing.Size(75,23)
    $OKButton.Text = "OK"
    $OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
    $form.AcceptButton = $OKButton
    $form.Controls.Add($OKButton)

    $CancelButton = New-Object System.Windows.Forms.Button
    $CancelButton.Location = New-Object System.Drawing.Point(150,120)
    $CancelButton.Size = New-Object System.Drawing.Size(75,23)
    $CancelButton.Text = "Cancel"
    $CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
    $form.CancelButton = $CancelButton
    $form.Controls.Add($CancelButton)

    $label1 = New-Object System.Windows.Forms.Label
    $label1.Location = New-Object System.Drawing.Point(10,20) 
    $label1.Size = New-Object System.Drawing.Size(280,20) 
    $label1.Text = "Please enter the quantity:"
    $form.Controls.Add($label1) 

    $textBox1 = New-Object System.Windows.Forms.TextBox 
    $textBox1.Location = New-Object System.Drawing.Point(10,40) 
    $textBox1.Size = New-Object System.Drawing.Size(260,20) 
    $form.Controls.Add($textBox1) 

    $label2 = New-Object System.Windows.Forms.Label
    $label2.Location = New-Object System.Drawing.Point(10,60) 
    $label2.Size = New-Object System.Drawing.Size(280,20) 
    $label2.Text = "Please enter the PO number"
    $form.Controls.Add($label2) 

    $textBox2 = New-Object System.Windows.Forms.TextBox 
    $textBox2.Location = New-Object System.Drawing.Point(10,80) 
    $textBox2.Size = New-Object System.Drawing.Size(260,20) 
    $form.Controls.Add($textBox2) 

    $form.Topmost = $True

    $form.Add_Shown({$textBox1.Select()})
    $form.Add_Shown({$textBox2.Select()})
    $result = $form.ShowDialog()

    if ($result -eq [System.Windows.Forms.DialogResult]::OK)
    {
    $li = get-scsmclass -name cireson.assetmanagement.purchase; 
    $liname = $cat + " - "+ $textbox2.text; 
    $props = @{Name = $liname; UnitCost = $cost; Units = $textbox1.text}; 
    new-scsmclassinstance -class $li -property $props;
    write-host $liname "created" $result
    $poid = $textBox2.text
    $po = Get-SCSMClassInstance -Class (get-scsmclass -Name cireson.assetmanagement.purchaseorder) -Filter "name -eq $poid"
    write-host $po.'#name' "selected"
    IF ($po){$lineitem = Get-SCSMClassInstance -Class (get-scsmclass -Name cireson.assetmanagement.purchase) -Filter "name -eq $liname"
    New-SCRelationshipInstance -RelationshipClass (Get-SCSMRelationship -Id "809152B3-D6A3-BF05-C602-CF446669A9F1") -Source $lineitem -Target $po
    write-host "purchase linked to po"} ELSE {write-host "PO Missing"}
    }
    else
    {write-host "Cancelled"}
  • Alex_MarshAlex_Marsh Premier Partner Advanced IT Monkey ✭✭✭
    I'd be interested to see how this could work on the portal as well as it would save having to switch between the console and the portal
Sign In or Register to comment.