How to add hyperlink for g_form.showFieldMsg display message

poornima batchu
Tera Expert

Hi all, 

I'm trying to add a hyperlink for g_form.showFieldMsg which redirects to a portal. I have seen in the community it is not possible for showfiledMsg. client is expecting only display message they are not okay to add it as an info message

Could anyone suggest the best alternative ways to achieve this? 

17 REPLIES 17

but it should work only for particular choice

Amit Gujarathi
Giga Sage
Giga Sage

HI @poornima batchu ,
I trust you are doing great.

Hello Poornima,

In ServiceNow, the g_form.showFieldMsg() function is typically used to display informational, error, or warning messages related to a specific field on a form. However, as you've found, it does not natively support the inclusion of hyperlinks directly within the message.

Given your requirement to include a hyperlink in a field message without using an info message, you might consider a couple of alternative approaches:

1. Custom HTML Field

You can create a custom HTML field that contains the hyperlink. This field can be dynamically shown or hidden based on certain conditions. Here’s a basic outline on how to do this:

  • Create a new field: Add a new field of type 'HTML' to your form.
  • Set the HTML content: In this field, you can write HTML code that includes your hyperlink.
  • Control visibility: Use g_form.setVisible('field_name', true/false) to show or hide this field based on your specific conditions.

2. UI Macro

Another approach is to use a UI Macro to create a custom display message with a hyperlink. You can then embed this UI Macro in a form where needed. This approach offers more flexibility in terms of formatting and interaction but is more complex to implement.

  • Create a UI Macro: Design a UI Macro with the desired message and hyperlink.
  • Embed in the form: Use a UI Script or a client script to embed this macro into your form.

Sample Code

Here's a simple example of how you might implement the first approach:

    g_form. showFieldMsg('Field', message); // Replace 'your_html_field' with the actual field name

//message exampe : <a href="https://yourportal.com">Click here to go to the portal</a>


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



hello, 

Thanks for your reply but this needs to be implemented for variable and there is a certain condition applied on this variable..Say the varibale name is country --for India value only the display message should pop up. Display message should contian..Please submit your request through xyz.com (I need to provide the hyperlink for xyz.com).

Please provide the solution.

AshishKM
Kilo Patron
Kilo Patron

Hi @poornima batchu , 

You can configure portal URL in instruction section in the same question variable.

g_form.showFieldMsg bind with a field-name and display the msg at bottom, formatted help text also display at bottom.

 

AshishKMishra_0-1701793293000.png

 

-Thanks,

AshishKMishra


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

hello, 

Thanks for your reply but this needs to be implemented for variable and there is a certain condition applied on this variable..Say the varibale name is country --for India value only the display message should pop up. Display message should contian..Please submit your request through xyz.com (I need to provide the hyperlink for xyz.com).

Please provide the solutions