Skip to main content

HelloID

Add, edit, or remove a product task

For more information, see Product tasks.

Add a product task
  1. Go to Self Service > Products and click Edit for the relevant product.

  2. Go to the Actions tab.

  3. Click Add Product Task.

  4. 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.

    2022-06-13_15-43-13.png
  5. Change the task's default Name.

    For this example, we'll use Product task: Add AD user to AD group.

  6. 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.

  7. Enter the required input values for the task.

    2022-12-05_15-15-40.jpg

    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.}}).

    2023-08-11_12-33-51.jpg
  8. Click Update Action.

  9. 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.

    2022-12-05_15-13-29.jpg
  10. 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.

  1. Go to Self Service > Products and click Edit for the relevant product.

    For this example, we'll edit our Google Chrome product.

  2. Go to the Actions - New tab.

  3. 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.

    2023-08-07_11-36-54.jpg
  4. Enter a Name for the task.

    For this example, we'll call it Product task: Google Chrome: Approved.

    2023-08-07_11-37-28.jpg
  5. Click Add Product Task.

    The task editor is shown.

    2023-09-25_13-02-56.jpg
  6. Click Set Default Script to populate the task with a default script template.

    2023-09-25_13-05-05.jpg
    2023-09-25_13-05-58.jpg

    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.

  7. 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
    2023-09-25_13-43-18.jpg
  8. 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"
       }
    }
    2023-09-25_13-44-14.jpg
  9. 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.

    2023-09-25_13-45-18.jpg
    2023-09-25_13-46-39.jpg
  10. Preview any email sends on the Notifications tab.

    2023-09-25_13-47-49.jpg
  11. Click Update.

  12. 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
  1. Go to Self Service > Products and click Edit for the relevant product.

  2. Go to the Actions tab.

  3. For the relevant pre-defined product task, click Edit.

    2023-08-09_14-45-31.png
  4. Continue by following the instructions in Add a pre-defined product task.

Edit a PowerShell product task
  1. Go to Self Service > Products and click Edit for the relevant product.

  2. Go to the Actions - New tab.

  3. Click the relevant State.

  4. For the relevant task, click Edit Product Task.

    2023-08-09_14-39-00.jpg
  5. Continue by following the instructions in Add a PowerShell product task.

Remove a pre-defined product task
  1. Go to Self Service > Products and click Edit for the relevant product.

  2. Go to the Actions tab.

  3. For the relevant pre-defined product task, click Delete.

  4. To confirm, click Delete Action.

  5. Click Save.

Remove a PowerShell product task
  1. Go to Self Service > Products and click Edit for the relevant product.

  2. Go to the Actions - New tab.

  3. Click the relevant State.

  4. For the relevant task, click Delete Product Task.

  5. To confirm, click Delete.

  6. Click Save.