There are currently two main options used to run PowerShell scripts from ServiceDesk Plus, the ‘Request Custom Menu’ or ‘Custom Trigger’ options, available from ‘Admin > HelpDesk Customiser’. Both of these configurations will have an option to execute a script and, in order to run a PowerShell script, you will need to use the following command as an ‘Execute Script’ action:
So for a real scenario … one client we were working with had a new starter process that required an email to be delivered to a specific team that were not part of the ServiceDesk installation with details of the ticket if a particular level of access was requested.
In order to achieve this we designed a Service Request template with all the necessary data fields and resource elements to collect the required data for the new starter process. On this template was a specific custom field that we used to specify the particular access level and this was used as a trigger condition for a ‘Custom Trigger’ with the full request data being passed to the script as $COMPLETE_JSON_FILE.
An example is shown below:
Here is the PowerShell script we created to send the email with the required contents of the request; the actual script also included a large number of custom fields but I’ve only included the standard SDP request fields in this example. I’ve also kept the data in the JSON format as this easier to relate to and test when using the API Documentation feature in the ServiceDesk Plus Admin tab. Remember to save your script file to the ‘integrationcustom_scripts’ folder if you’re going to test a copy:
——– Start of script ——-
# V1.0 Initial release
# V1.1 Updated to use API to send Email as Reply to Request rather than PowerShell
# MailMessage Cmdlet
# Store request data passed to script – this must be first element in script
param (
$json = “none”
)
$jsondata = Get-Content $json -Encoding UTF8 #Encode if necessary
$obj = ConvertFrom-Json $jsondata
# Add Request fields values as needed – custom fields are referenced by their alias name
$workorderid = $obj.request.WORKORDERID
$requester = $obj.request.REQUESTER
$createdtime = $obj.request.createdtime
$subject = $obj.request.SUBJECT
$category = $obj.request.category
$technician = $obj.request.technician
$status = $obj.request.status
$priority = $obj.request.priority
$requesttype = $obj.request.requesttype
$group = $obj.request.group
$description = $obj.request.description
# Set system parameters – change these details to suit your system environment
$sdphost = “http://[hostname or IP address]:[port]/”
$techkey = “[your technician API key]”
# Set API module URL and operation – this is the URL for calling the request API
# It uses the request parameter passed to the script $workorderid
$url = $sdphost + “sdpapi/request/” + $workorderid
$method = “POST”
$operation = “REPLY_REQUEST”
# Define Email Content
$to = ” [insert to email address here] ”
$cc = ” [insert cc email address here] ”
$subject = “New Starter Alert”
# email description text
$body = “Request Number : $workorderid, Requester : $requester, Subject : $subject, Category : $category, Technician: $technician, Status : $status, Priority : $priority, Request Type: $requesttype, Group : $group”
# Configure input data for email Reply operation in JSON format
$inputdata = @”
{
“operation”: {
“details”: {
“to”: “$to”,
“cc”: “$cc”,
“subject”: “$subject”,
“description”: “$body”
}
}
}
“@
# Configure paramaters for web API call as an array of object and format as JSON data – this is a more elegant method than creating a text string to build the URL
# Make a web API call and record result
$response = Invoke-WebRequest -Uri $url -Method POST -Body $params
——– End of script ——-
I hope this series of blog articles has been useful. I’m finding that there are ever more customer requirements for using scripts and the API in general. I will be including more examples in future posts and also uploading them to the Forum Resources but that’s all on the ServiceDesk Plus API for now.
Enjoy!
This article is relevant to:
Service DeskOther recent articles in the same category
You may be interested in these other recent articles
Third Party Integration with ServiceDesk Plus: A Standardised Approach
5 February 2025
In today’s fast-paced IT landscape, businesses rely on third-party application integrations to streamline workflows and enhance operational efficiency. To unlock the full potential of these…
Read moreExport Contracts in ServiceDesk Plus: A Practical Solution
30 January 2025
Find out how customers who need to export contracts from ServiceDesk Plus come to Set3 Solutions for expert guidance.
Read moreLatest Updates for ManageEngine Endpoint Central
27 January 2025
Discover the latest Endpoint Central updates, including new features, fixes, and enhancements.
Read moreStay Ahead with the Latest Updates for ManageEngine OpManager
22 January 2025
Discover the latest OpManager updates, including new features, fixes, and enhancements.
Read moreLatest Updates for ManageEngine ServiceDesk Plus Cloud
18 January 2025
Discover the latest ServiceDesk Plus Cloud updates, including new features, fixes, and enhancements.
Read more