Info Messsage with button in Service Operation Workspace.

Pablo Sanz
Tera Guru

 

Requirement:

Currently in the Incident form there is an infoMessage with a button that sets certain values in the form, which is coded as follows:

 

<button onclick="g_form.setValue(\'service_offering\', \'' + result[2] + '\'); g_form.clearMessages()">' + Click Here + '</button>

 

This button works in the Incident form in platform, when I try to replicate the same operation in SOW it does not perform any action.

 

Reviewing the code of the page, it seems that the "onClick" event is not detected in SOW.

 

Is there any alternative to replicate this functionality in SOW? The reason why these messages are used is because sometimes it shows up to 2 messages at the same time, so the user has the opportunity to select the appropriate one for his scenario.

 

Thanks in advance.

3 REPLIES 3

Haseeb-Ahmed
ServiceNow Employee
ServiceNow Employee

Hi @Pablo Sanz ,

you may populated info message like below

 

For Demo:

1. created server type declarative action with below code 

 
var incLink = '<a href="' + "now/sow/record/incident/incident_sys_id" + '">' + "Click" + '</a>';
gs.addInfoMessage(gs.getMessage("{0} click to open", [incLink]));
 
2. on click of that info message with clickable link will be shown
 
Screenshot 2024-02-09 at 4.03.27 PM.pngScreenshot 2024-02-09 at 4.02.19 PM.png
 

Please accept the solution or give a thumbs up if it answers your query.

Thanks,
Haseeb Ahmed

 

Thanks for your suggestion, in my case I need to fill in some information in the Incident form.

Rajdeep Ganguly
Mega Guru


In ServiceNow Workspace (SOW), the traditional client-side scripting methods like g_form, g_user, etc. are not supported. Instead, ServiceNow has introduced a new client-side scripting API called 'now-*' components.

To replicate the functionality of the button in SOW, you can use the 'now-button' component. Here are the steps:

1. Create a new UI Action with the following properties:
- Name: Set Values
- Action name: set_values
- Client callable: true
- Script:

function() {
g_form.setValue('service_offering', result[2]);
g_form.clearMessages();
}


2. In your Workspace view, add a new 'now-button' component with the following properties:
- Label: Click Here
- Action: set_values

3. The 'now-button' component will call the 'set_values' UI Action when clicked, replicating the functionality of the button in the platform view.

Please note that the 'now-*' components are only available in the New York release and later. If you are on an earlier release, you will need to upgrade to use these components.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER