Jump to content

serviceId not parsing when I call logIncident API Operation


Recommended Posts

I have the following code:

 

function New-HBIncident {
<#
.Synopsis
   Script to logs a new incident in Hornbill.

.DESCRIPTION
  The script logs a new incident in Hornbill.

.LINK
  https://ukipo.visualstudio.com/IT%20Operations/_git/Powershell?path=/Morning_Checks

.NOTES
  Version:  1.0
  Author:	Robert Gething/Mark White
  Created:	09.02.2023
  Updated:	
  History:	1.0 - Initial script release

#.PARAMETER instanceName
#MANDATORY: The name of the Instance to connect to.

#.PARAMETER instanceKey
#MANDATORY: An API key with permission on the Instance to carry out the required API calls.

#.PARAMETER assetIds
#A comma-seperated string of asset IDs to attach to the new request, for example: 1,12,36

#.PARAMETER bpmName
#The name of a BPM to override the Service BPM or Default BPM.

#.PARAMETER catalogName
#The title of the catalog to raise thew request against

#.PARAMETER categoryId
#The ID of the request category

#.PARAMETER categoryName
#The fullname of the request category

#.PARAMETER customerId
#The ID of the request customer

#.PARAMETER customerType
#The Type of the request customer (0 for Users, 1 for contacts)

#.PARAMETER description
#The request description

#.PARAMETER ownerId
#The ID of the request owner

#.PARAMETER priorityName
#The name of the request Priority

#.PARAMETER resolutionDetails
#The resolution description

#.PARAMETER serviceName
#The name of the service to raise the request against

#.PARAMETER siteName
#The name of the request site

#.PARAMETER sourceId
#The ID of the request source

#.PARAMETER sourceType
#The Type of request source

#.PARAMETER status
#The status of the new request (defaults to status.open)

#.PARAMETER summary
#The request summary

#.PARAMETER teamId
#The ID of the team that the request should be assigned to

#Requires -Module @{ModuleVersion = '1.1.0'; ModuleName = 'HornbillAPI'}
#Requires -Module @{ModuleVersion = '1.1.1'; ModuleName = 'HornbillHelpers'}
#>
	# Define output stream type
	[OutputType([object])]
	# Define runbook input params
	Param
	(
		
		# API Params
		[string]$assetIds,
		[string]$bpmName,
		[string]$catalogName,
		[string]$categoryId,
		[string]$categoryName,
		[string]$customerId,
		[string]$customerType,
		[string]$description,
		[string]$ownerId,
		[string]$priorityName,
		[string]$resolutionDetails,
		[string]$serviceName,
		[string]$siteName,
		[string]$sourceId,
		[string]$sourceType,
		[string]$status,
		[string]$summary,
		[string]$teamId
	)
	
	# Get service ID from Name
	$serviceId = ""
	if ($serviceName -and $serviceName -ne "")
	{
		$serviceObj = Get-HB-ServiceID $serviceName
		if ($serviceObj.ServiceID -gt 0)
		{
			$serviceId = $serviceObj.ServiceID
		}
	}
	
	# Get Priority ID from Name
	$priorityId = ""
	if ($priorityName -and $priorityName -ne "")
	{
		$priorityObj = Get-HB-PriorityID $priorityName
		if ($priorityObj.PriorityID -gt 0)
		{
			$priorityId = $priorityObj.PriorityID
		}
	}
	
	# Get Catalog ItemID from Name
	$catItemId = ""
	if ($catalogName -and $catalogName -ne "")
	{
		$catalogObj = Get-HB-CatalogID $catalogName $serviceName "Incident"
		if ($catalogObj.CatalogID -gt 0)
		{
			$catItemId = $catalogObj.CatalogID
		}
	}
	
	# Get SiteID from Name
	$siteId = ""
	if ($siteName -and $siteName -ne "")
	{
		$siteObj = Get-HB-SiteID $siteName
		$siteId = $siteObj.SiteID
	}
	
	# Populate status if null
	if (-not $status -or $status -eq "")
	{
		$status = "status.open"
	}
	
	Add-HB-Param "summary" $summary $false
	Add-HB-Param "description" $description $false
	Add-HB-Param "customerId" $customerId $false
	Add-HB-Param "customerType" $customerType $false
	Add-HB-Param "ownerId" $ownerId $false
	Add-HB-Param "teamId" $teamId $false
	Add-HB-Param "status" $status $false
	Add-HB-Param "priorityId" $priorityId $false
	Add-HB-Param "categoryId" $categoryId $false
	Add-HB-Param "categoryName" $categoryName $false
	Add-HB-Param "sourceType" $sourceType $false
	Add-HB-Param "sourceId" $sourceId $false
	
	# Process Assets
	if ($assetIds)
	{
		$arrAssets = $assetIds.replace(' ', '').split(',')
		foreach ($asset in $arrAssets)
		{
			Add-HB-Param "assetId" $asset $false
		}
	}
	
	Add-HB-Param "serviceId" $serviceId $false
	Add-HB-Param "resolutionDetails" $resolutionDetails $false
	Add-HB-Param "siteId" $siteId $false
	Add-HB-Param "siteName" $siteName $false
	Add-HB-Param "catalogId" $catItemId $false
	Add-HB-Param "catalogName" $catalogName $false
	Add-HB-Param "bpmName" $bpmName $false
	
	# Invoke XMLMC call, output returned as PSObject
	$xmlmcOutput = Invoke-HB-XMLMC "apps/com.hornbill.servicemanager/Incidents" "logIncident"
	
	$exceptionName = ""
	$exceptionSummary = ""
	# Read output status
	if ($xmlmcOutput.status -eq "ok")
	{
		if ($xmlmcOutput.params.requestId -and $xmlmcOutput.params.requestId -ne "")
		{
			$requestRef = $xmlmcOutput.params.requestId
			$requestWarnings = $xmlmcOutput.params.warnings
		}
		if ($xmlmcOutput.params.exceptionName -and $xmlmcOutput.params.exceptionName -ne "")
		{
			$exceptionName = $xmlmcOutput.params.exceptionName
			$exceptionSummary = $xmlmcOutput.params.exceptionDescription
		}
	}
	# Build resultObject to write to output
	$resultObject = New-Object PSObject -Property @{
		Status		     = $xmlmcOutput.status
		Error		     = $xmlmcOutput.error
		RequestRef	     = $requestRef
		Warnings		 = $requestWarnings
		ExceptionName    = $exceptionName
		ExceptionSummary = $exceptionSummary
	}
	
	if ($resultObject.Status -ne "ok")
	{
		Write-Error $resultObject
	}
	else
	{
		if ($exceptionName -ne "")
		{
			Write-Warning $resultObject
		}
		else
		{
			Write-Output $resultObject
		}
	}
}

#Connect to Hornbill API
Write-Verbose "Connecting to Hornbill..."
Set-HB-Instance -Instance $instance -Key $key
Set-HB-Proxy -ProxyAddress $proxy

$serviceName = "2. Request Something"
$catalogName = "Raise a request with IT support"
$priorityName = "Priority 3"
$NewHBIncidentParams = @{
	dummary = "Test"
	description = "Test"
	customerId = "HORNL"
	customerType = 0
	teamId  = "IPO/IT/OPS/APPSL2/"
	status  = "status.open"
	priorityId = 18
	sourceType = "Automated Morning Checks"
    serviceId = "555"
	siteId  = 1
	siteName = "Concept House, Cardiff Road"
}
$NewIncident = New-HBIncident @NewHBIncidentParams

When I try to add:

bpmName = "morning-checks-automation"

I get:

{"logRequestBpmFailed":"There was an error in the starting the BPM process for this request. Details: 
                   defaultProcessNotSet - undefined"}

The workflow is set and the service is available:

image.thumb.png.102c6337728b48551294bd424d0ce06b.png

 

When I try to use:
 

# Define output stream type
    [OutputType([object])]

    # Define runbook input params
    Param
    (
        # API Params
        [string] $requestId = "IN00220363",
        [string] $defaultBpm = 'morning-checks-automation'
        )

    Set-HB-Instance -Instance $instance -Key $key
    Set-HB-Proxy -ProxyAddress $proxy

    # Add XMLMC params
    Add-HB-Param "requestId" $requestId $false
    Add-HB-Param "defaultBpm" $defaultBpm $false

   # Invoke XMLMC call, output returned as PSObject
   $xmlmcOutput = Invoke-HB-XMLMC "Requests" "logRequestBPM"
   $exceptionName = "" 
   $exceptionSummary = ""
   
    # Read output status
    if($xmlmcOutput.params.bpmProcessId -and $xmlmcOutput.params.bpmProcessId -ne ""){
            $bpmProcessId = $xmlmcOutput.params.bpmProcessId
            $requestWarnings = $xmlmcOutput.params.warnings
        }
        if($xmlmcOutput.params.exceptionName -and $xmlmcOutput.params.exceptionName -ne ""){
            $exceptionName = $xmlmcOutput.params.exceptionName
            $exceptionSummary = $xmlmcOutput.params.exceptionDescription
        }
    
    # Build resultObject to write to output
    $resultObject = New-Object PSObject -Property @{
        Status = $xmlmcOutput.status
        Error = $xmlmcOutput.error
        ExceptionName = $exceptionName
        ExceptionSummary = $exceptionSummary
        bpmProcessId = $bpmProcessId
        }

    if($resultObject.Status -ne "ok" -or $exceptionName -ne ""){
        Write-Error $resultObject
    } else {
        Write-Output $resultObject
       }

I get:

@{Status=fail; Error=The service 
specified is not available: Requests; bpmProcessId=; ExceptionName=; ExceptionSummary=}

I presume this is because the serviceId is not being parsed, but when I try to parse a serviceId i.e. 551, the service still fails to link to the request.

Where am I going wrong here?

Link to comment
Share on other sites

  • 4 weeks later...
  • 1 month later...

I believe the issue is because the screenshot which shows the Incident Configuration (which a slider on the right to activate is turned off).

image.png.468cae7ba2a4d3b1462552f05759dd79.png

I was seeing the same error:

"warnings":"{\"logRequestBpmFailed\":\"There was an error in the starting the BPM process for this request. Details: defaultProcessNotSet - undefined\"}"

until I had spotted my mistake.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...