Requires
Last active
August 29, 2015 14:20
-
-
Save Sam-Martin/cffb35d1f593202525c3 to your computer and use it in GitHub Desktop.
Sync ServiceNow to Leankit using PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module PSLeankit | |
Import-Module PSServiceNow | |
# Set-LeanKitAuth | |
# Set-ServiceNowAuth | |
# We need to know the boardID, we'll infer any other information | |
$boardID = [array](Find-LeanKitBoard) | ?{$_.Title -eq "Sam's Board"} | select -ExpandProperty id; | |
# Set defaults | |
$board = Get-LeankitBoard -boardID $boardID | |
$DropLaneID = $board.DefaultDropLaneId | |
$doneLaneID = $board.lanes | ?{$_.type -eq 3} | select -first 1 | select -ExpandProperty id | |
$CardTypeID = $board.CardTypes | ?{$_.name -eq "Task"} | select -ExpandProperty id; | |
#$UserGroup = Get-ServiceNowUserGroup -MatchExact @{'name'='Cloud Ops Architect Team '} | |
$User = Get-ServiceNowUser -MatchExact @{name="Sam Martin"} | |
# Get cards and incidents | |
$cards = $board.Lanes.cards + $board.Archive + $board.Backlog.Cards | |
#$incidents = Get-ServiceNowIncident -MatchExact @{'assignment_group'=$UserGroup.sys_id;'active'='true'} -Limit 999 | |
$incidents = Get-ServiceNowIncident -MatchExact @{'assigned_to'=$user.sys_id;'active'='true'} -Limit 999 | |
$PriorityMapping = @{ | |
"1 - Critical" = 3 | |
"2 - High" = 2 | |
"3 - Medium" = 1 | |
"4 - Low" = 0 | |
} | |
$stateMapping = @{ | |
default = $DropLaneID | |
Resolved = $doneLaneID | |
} | |
$CategoryMapping = @{ | |
default = $board.CardTypes | ?{$_.name -eq "Task"} | |
<# Request = $board.CardTypes | ?{$_.name -eq "Task"} | |
Server = $board.CardTypes | ?{$_.name -eq "Server"} | |
Application = $board.CardTypes | ?{$_.name -eq "Application"} | |
Database = $board.CardTypes | ?{$_.name -eq "Database"} | |
Network = $board.CardTypes | ?{$_.name -eq "Network"} | |
Maintenance = $board.CardTypes | ?{$_.name -eq "Maintenance"} | |
Internal = $board.CardTypes | ?{$_.name -eq "Internal"} | |
"Sales Support" = $board.CardTypes | ?{$_.name -eq "Sales Support"} | |
Security = $board.CardTypes | ?{$_.name -eq "Security"} #> | |
} | |
# Compare the cards with the incidents, and create cards for any incidents which don't have them already | |
foreach($incident in $incidents){ | |
$card = $($cards| ?{$_.ExternalCardID -eq $incident.number}) | |
$cardType = if($CategoryMapping.($incident.category)){$CategoryMapping.($incident.category)}else{$CategoryMapping.default} | |
if($stateMapping.($incident.state)){ | |
$laneID = $stateMapping.($incident.state) | |
}if($cardID){ | |
$laneID = $card.LaneId | |
}else{ | |
$laneID = $stateMapping.default | |
} | |
if(!$cardID){ | |
$result = Add-LeanKitCard -BoardID $boardID ` | |
-Title $incident.short_description ` | |
-Description $incident.description ` | |
-ExternalCardID $incident.number ` | |
-Priority $PriorityMapping.($incident.priority) ` | |
-CardTypeID $CardTypeID ` | |
-LaneID $laneID ` | |
-UserWipOverrideComment 'None' | |
}else{ | |
$result = Update-LeanKitCard -BoardID $boardID ` | |
-CardID $card.id ` | |
-Title $incident.short_description ` | |
-Description $incident.description ` | |
-ExternalCardID $incident.number ` | |
-Priority $PriorityMapping.($incident.priority) ` | |
-CardTypeID $CardTypeID ` | |
-LaneID $laneID ` | |
-UserWipOverrideComment 'None' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment