Add, edit, or remove a product task
For more information, see Product tasks.
Add a product task
Go to Self Service > Products and click Edit for the relevant product.
Go to the Actions tab.
Click Add Product Task.
In the Task catalog dialog box, search for the pre-defined task that you want to create.
For this example, we'll add the Add AD user to AD group task.
Optional: Change the task's default Name.
For this example, we'll use
Product task: Add AD user to AD group
.Set Execute On State to the stage of the Product request lifecycle when this script should be executed.
For this example, we'll set it to Approved.
Enter the required input values for the task.
Tip
Type
{{
in a text field to activate autocomplete.You have access to $manager, $product, $request, $requester, and $resourceOwnerGroup. You also have access to System variables (under {{portal.}}) and Custom variables (under {{variable.}}).
Click Update Action.
Optional: Add additional tasks for other stages of the Product request lifecycle.
For example, here we've added the Remove AD user from AD group task to the product's Returned stage.
Click Save.
The task(s) will run during the appropriate lifecycle stage(s) during users' Product requests for this product.
Note
Prerequisites: The Google Chrome
product shown in the Add a product article, and the Weather report
form shown in the Add a dynamic form article.
Go to Self Service > Products and click Edit for the relevant product.
For this example, we'll edit our Google Chrome product.
Go to the Actions - New tab.
In the States pane, select the state of the Product request lifecycle during which this task will run.
For this example, we'll select the Approved state.
Enter a Name for the task.
For this example, we'll call it
Product task: Google Chrome: Approved
.Click Add Product Task.
The task editor is shown.
Click Set Default Script to populate the task with a default script template.
Tip
To start over at any time, delete all text from the script field. The Set Default Script button reappears.
The key points about the script template are as follows. Examples are shown later in this article.
Wrap your code in a try/catch block.
On the Code Snippet Library tab, you can use the topic filter menu and search bar to find useful PowerShell snippets to copy & paste into your script. Click a snippet's Copy To Clipboard button to copy it, or alternatively click its title to preview its code, readme, and release notes. For more information on using snippets, see PowerShell product task snippets on GitHub.
Two types of logging are available: PowerShell console logging, and HelloID audit logging. See Logging in PowerShell product tasks and Audit logging in PowerShell product tasks. You can preview your PowerShell logs on the Received Logs tab, and your audit logs on the Received Audit Logs tab.
You have access to the following variables through autocomplete: $approvalHistory, $form, $manager, $product, $request, $requester, and $requestedFor. Open autocomplete by typing
$
. You also have access to all System variables, Custom variables, which are not included in autocomplete.Use the Run In Cloud toggle to choose whether this script will run using the Cloud Service Automation Agent (enabled) or the On-premises Service Automation Agent (disabled).
The Input tab lets you specify JSON form input in order to test scripts that use the $form variable.
Tip
To generate test JSON based on a form, Generate test JSON.
Email sends in PowerShell product tasks are supported, and you can preview them on the Notifications tab.
PowerShell product task scripts should not return any data to HelloID.
Customize the script according to what should happen during the selected stage of the product lifecycle for this product. For example, make API calls into external systems based on the data available in the product, the request, etc.
For this example, we will query a weather API, and show some important variables in action. We'll use the following script:
####################################################################### # Template: HelloID SA PowerShell product action # Name: Google Chrome: Approved # Date: 8.7.2023 ####################################################################### #region init $VerbosePreference = "SilentlyContinue" $InformationPreference = "Continue" $WarningPreference = "Continue" # global variables (Automation --> Variable library): $globalVarExample = $companyName # product variables: $requesterUsernameExample = $requester.userName $requesterUserGUIDExample = $requester.userGUID $productNameExample = $product.name # variables configured in form: $formVarExample = $form.tempUnitDropdown.tempUnitValue #endregion init #region functions Function Get-Current-NYC-Weather { $locationEndpoint = "https://api.open-meteo.com/v1/forecast?latitude=40.71&longitude=-74.01&hourly=temperature_2m&temperature_unit=$formVarExample&windspeed_unit=mph&precipitation_unit=inch" $response = Invoke-RestMethod -uri $locationEndpoint Write-Information "Response: $response" return @{weather = "Current time: $($response.hourly.time[0]); current temperature: $($response.hourly.temperature_2m[0]) degrees $formVarExample"} } #endregion functions #region task try { Write-Verbose "Looking up NYC weather for [$requesterUsernameExample ($requesterUserGUIDExample)] at $globalVarExample, in product $productNameExample" $result = Get-Current-NYC-Weather Write-Information "Result: $($result.weather)" $Log = @{ Action = "Undefined" System = "OpenMeteo" Message = "Successfully executed action for [$requesterUsernameExample ($requesterUserGUIDExample)]" IsError = $false TargetDisplayName = $requesterUsernameExample TargetIdentifier = $([string]$requesterUserGUIDExample) } Write-Information -Tags "Audit" -MessageData $log $email = @{ from = "[email protected]" to = "[email protected]" subject = "Your weather report" body = "<strong>$($result.weather)</strong>" confidential= $false } Write-Information -Tags "Email" $email } catch { $ex = $PSItem Write-Warning "Error at Line '$($ex.InvocationInfo.ScriptLineNumber)': $($ex.InvocationInfo.Line). Error: $($ex.Exception.Message)" Write-Error "Error executing action for [$requesterUsernameExample ($requesterUserGUIDExample)]. Error Message: $($ex.Exception.Message)" $Log = @{ Action = "Undefined" System = "OpenMeteo" Message = "Error executing action for [$requesterUsernameExample ($requesterUserGUIDExample)]. Error Message: $($ex.Exception.Message)" IsError = $true TargetDisplayName = $requesterUsernameExample TargetIdentifier = $([string]$requesterUserGUIDExample) } Write-Information -Tags "Audit" -MessageData $log } #endregion task
If your script relies on form data, enter JSON in the Input tab to simulate form input.
For this example, we'll enter the following JSON to simulate input from our
Weather report
form:{ "tempUnitDropdown": { "tempUnitLabel": "Fahrenheit", "tempUnitValue": "fahrenheit" } }
To test your script, click Execute PowerShell. View the results on the Received Logs and Received Audit Logs tabs.
For this example, the NYC weather has been fetched and logged.
Preview any email sends on the Notifications tab.
Click Update.
Click Save.
The task(s) will run during the appropriate lifecycle stage(s) during users' Product requests for this product.
Edit a pre-defined product task
Go to Self Service > Products and click Edit for the relevant product.
Go to the Actions tab.
For the relevant pre-defined product task, click Edit.
Continue by following the instructions in Add a pre-defined product task.
Edit a PowerShell product task
Go to Self Service > Products and click Edit for the relevant product.
Go to the Actions - New tab.
Click the relevant State.
For the relevant task, click Edit Product Task.
Continue by following the instructions in Add a PowerShell product task.
Remove a pre-defined product task
Go to Self Service > Products and click Edit for the relevant product.
Go to the Actions tab.
For the relevant pre-defined product task, click Delete.
To confirm, click Delete Action.
Click Save.
Remove a PowerShell product task
Go to Self Service > Products and click Edit for the relevant product.
Go to the Actions - New tab.
Click the relevant State.
For the relevant task, click Delete Product Task.
To confirm, click Delete.
Click Save.