--- title: g\_modal \(Next Experience\) - Client description: The g\_modal API enables you to display a modal window to enhance application functionality.Displays an alert message relating to a UI action.Displays a confirm message relating to a UI action.Displays a confirm message related to a UI action, with the confirm button displaying a destructive style.Displays a modal that uses passed HTML to generate the content within the modal.Displays a modal window that contains the specified fields and an OK and Cancel buttons by default.Displays a modal that uses a link to an external URL or UI page for its content. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/api-reference/g\_modalClientAPINX.html release: australia product: API Reference classification: api-reference topic_type: concept last_updated: "2026-03-12" reading_time_minutes: 18 breadcrumb: [Client Next Experience API reference, API reference, API implementation and reference] --- # g\_modal \(Next Experience\)- Client The g\_modal API enables you to display a modal window to enhance application functionality. Use this API to display modals in workspaces. Using this API you can: - Display input type fields in a modal window. - Show something in a frame such as a UI page or external link. - Perform an action on user confirmation. - Load a component. - Use HTML to populate the contents of a modal. **Parent Topic:**[Client Next Experience API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/api-client-next.md) ## g\_modal \(Next Experience\) - alert\(String title, String message, Function callback, style Object\) Displays an alert message relating to a UI action.
Name Type Description
title String Optional. Title to display in the header of the modal.Default: Alert
message String Message to display in the modal body. **Note:** If you only pass one parameter, the method treats it as the **message** parameter.
callback Function Optional. Function to call after the form has been submitted and processed on the server. The callback function has the form `callbackFunction(String action_verb, String sys_id, String table, String displayValue)` where: - **action\_verb**: Name of the UI action executed. Examples: - sysverb\_cancel \(Cancel button\) - sysverb\_insert \(Submit button\) - sysverb\_save \(Save button\) - **sys\_id**: Sys\_id of the affected record. - **table**: Name of the table containing the record. - **displayValue**: Value that appears on the form. Default: No additional processing
style Object Optional. Style of the confirmation button to display in the modal.``` "style": { "buttonTitle": "String", "buttonType": "String" } ```
style.buttonTitle String Optional. Text to display on the confirmation button.Default: OK
style.buttonType String Optional. Type of confirmation button to display.Default: default
Type Description
Promise If a **callback** parameter is passed, returns promise if successful, error otherwise.If a **callback** parameter isn't passed, the method always returns success.
The following code example shows how to call this method to display an alert message 'Only the assigned to can end this action.'. ``` function onClick(g_form) { if (g_user.userID != g_form.getValue('assigned_to')) { g_modal.alert('Only the assigned to can end this action.'); return; } var msg = getMessage("Are you sure you want to take this action?"); g_modal.confirm(getMessage("Confirmation"), msg, function (confirmed) { if (confirmed) { g_form.setValue('state', 'closed_complete'); g_form.save(); } }); return false; } ``` ## g\_modal \(Next Experience\) - confirm\(String title, String message, Function callback, style Object\) Displays a confirm message relating to a UI action.
Name Type Description
title String Optional. Title to display in the header of the modal.Default: Confirm
message String Message to display in the modal body. **Note:** If you only pass one parameter, the method treats it as the **message** parameter.
callback Function Optional. Function to call after the form has been submitted and processed on the server. The callback function has the form `callbackFunction(String action_verb, String sys_id, String table, String displayValue)` where: - **action\_verb**: Name of the UI action executed. Examples: - sysverb\_cancel \(Cancel button\) - sysverb\_insert \(Submit button\) - sysverb\_save \(Save button\) - **sys\_id**: Sys\_id of the affected record. - **table**: Name of the table containing the record. - **displayValue**: Value that appears on the form. Default: No additional processing
style Object Optional. Style of the confirm and cancel buttons to display in the modal.``` "style": { "cancelTitle": "String", "cancelType": "String", "confirmTitle": "String", "confirmType": "String" } ```
style.cancelTitle String Optional. Text to display on the cancel button.Default: Cancel
style.cancelType String Optional. Type of cancel button to display.Valid values: - confirm \(blue background\) - default \(white background\) - destructive \(red background\) Default: confirm
style.confirmTitle String Optional. Text to display on the confirm button.Default: OK
style.confirmType String Optional. Type of confirm button to display.Valid values: - confirm \(blue background\) - default \(white background\) - destructive \(red background\) Default: default
Type Description
Promise If a **callback** parameter is passed, returns promise if successful, error otherwise.If a **callback** parameter isn't passed, the method always returns success.
The following code example shows how to call this method to display the confirmation message "Are you sure you want to take this action?" ``` function onClick(g_form) { if (g_user.userID != g_form.getValue('assigned_to')) { g_modal.alert('Only the assigned to can end this action.'); return; } var msg = getMessage("Are you sure you want to take this action?"); g_modal.confirm(getMessage("Confirmation"), msg, function (confirmed) { if (confirmed) { g_form.setValue('state', 'closed_complete'); g_form.save(); } }); return false; } ``` Output: \[Omitted image "g\_modal\_confirm-modal\_shot.png"\] Alt text: Screen shot that shows the confirm modal generated by the code ## g\_modal \(Next Experience\) - confirmDestroy\(String title, String message, Function callback, style Object\) Displays a confirm message related to a UI action, with the confirm button displaying a destructive style.
Name Type Description
title String Optional. Title to display in the header of the modal.Default: Confirm
message String Message to display in the modal body. **Note:** If you only pass one parameter, the method treats it as the **message** parameter.
callback Function Optional. Function to call after the form has been submitted and processed on the server. The callback function has the form `callbackFunction(String action_verb, String sys_id, String table, String displayValue)` where: - **action\_verb**: Name of the UI action executed. Examples: - sysverb\_cancel \(Cancel button\) - sysverb\_insert \(Submit button\) - sysverb\_save \(Save button\) - **sys\_id**: Sys\_id of the affected record. - **table**: Name of the table containing the record. - **displayValue**: Value that appears on the form. Default: No additional processing
style Object Optional. Style of the confirm and cancel buttons to display in the modal.``` "style": { "cancelTitle": "String", "cancelType": "String", "confirmTitle": "String", "confirmType": "String" } ```
style.cancelTitle String Optional. Text to display on the cancel button.Default: Cancel
style.cancelType String Optional. Type of cancel button to display.Valid values: - confirm \(blue background\) - default \(white background\) - destructive \(red background\) Default: confirm
style.confirmTitle String Optional. Text to display on the confirm button.Default: OK
style.confirmType String Optional. Type of confirm button to display.Default: destructive
Type Description
Promise If a **callback** parameter is passed, returns promise if successful, error otherwise.If a **callback** parameter isn't passed, the method always returns success.
This example displays a confirmation modal with a red **Cancel** button and a blue **Confirm** button. ``` function callback(value){ value ? console.log("confirm destroy callback") : console.log('cancel callback'); } function onClick(g_form) { g_modal.confirmDestroy("Confirm Destroy Title", "Confirm Destroy Message", callback, { cancelTitle: "Cancel", cancelType: "destructive", confirmTitle: "Confirm", confirmType: "confirm" }) .then( function test() { g_form.setValue("state', '7"); }, function fail() { g_form.setValue("state", 2) } ) } ``` ## g\_modal \(Next Experience\) - richText\(String title, String richText, Function callback, String size, String cancelTitle, String confirmTitle, String cancelType, String confirmType, Object resizableConfig\) Displays a modal that uses passed HTML to generate the content within the modal.
Name Type Description
title String Optional. Title to display in the header of the modal.Default: blank
richText String HTML content to display in the modal.**Note:** This method removes `