# Services

## JavaScript

The JavaScript runtime can be accessed with the JavaScript service. It allows for executing JavaScript on the client and optionally returning a response.

```powershell
function OnClick {
    #Don't return a value    
    $JavaScript.InvokeVoid("alert('Hello!')")
    
    #Return a value
    $Value = $JavaScript.Invoke("'String'")
    $Message.Success($Value)
}
```

## Messages

The message service is used to display messages to the end user. It is based on the `IMessageService`. You can find more information [here](https://antblazor.com/en-US/components/message#API).

```powershell
function OnClick {
   $Message.Success("Hello!")
}
```

## Notifications

The notification service is used to display messages the include more information that the message service. You can customize the title, message and icon. You can find more information [here](https://antblazor.com/en-US/components/notification).

```powershell
function OnClick {
    $Config = [AntDesign.NotificationConfig]::new()
    $Config.Message = "Title" 
    $Config.Description = "This is the body of the notification"
    $Notification.Open($Config)
}
```

## Navigation

The navigation service can be used to move between portal pages, admin pages and external pages. The navigation service is an instance of [NavigationManager](https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.components.navigationmanager?view=aspnetcore-8.0).

```powershell
function OnClick {
    $Navigation.NavigateTo("/portal/page/name")
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/portal/portal-widgets/services.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
