The CreatorCon Call for Content is officially open! Get started here.

How to add hyperlink in showfieldmssg() inn catalog item

SHALIKAS
Tera Guru

I want to add hyperlink as follows but it is not working

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
  g_form.clearMessages();
 
   var s=['database_server','application_server'];
   if(s.includes(newValue))
   {
   
    var help='<a href="https://ervice.com">Add a Business Application </a>request to add it to ServiceNow';
g_form.showFieldMsg('application',help,'info');
   }
   else{
    g_form.hideFieldMsg('application');
  }
 

}
 
But link is not getting created. How to do this
1 ACCEPTED SOLUTION

Juhi Poddar
Kilo Patron
Kilo Patron

Hello @SHALIKAS 

  • You cannot populate link using g_form.showfieldmsg().
  • The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

5 REPLIES 5

Juhi Poddar
Kilo Patron
Kilo Patron

Hello @SHALIKAS 

  • You cannot populate link using g_form.showfieldmsg().
  • The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You
Juhi Poddar

Viraj Hudlikar
Tera Sage
Tera Sage

@SHALIKAS Not possible.

is there any way?

Hi @SHALIKAS ,

 

You can do something like below in client script. You can change the text according to your need.

Again: DOM manipulation is not recommended but it is required then you can use below script.

Make sure to uncheck the filed on client script "Isolate script".

 

 

var targetField = 'short_description'; // Replace with your field name

    // HTML content to insert
    var htmlContent = '<div id="customHtml" style="margin-top: 10px;">' +
        '<a href="https://www.example.com" target="_blank">Click here for more information</a>' +
        '</div>';

    // Ensure the field exists on the form
    if (g_form.getControl(targetField)) {
        // Get the field's DOM element
        var fieldElement = g_form.getControl(targetField).parentNode;

        // Check if the custom HTML is already added to prevent duplicates
        if (!document.getElementById('customHtml')) {
            // Insert the HTML after the field
            var div = document.createElement('div');
            div.innerHTML = htmlContent;
            fieldElement.appendChild(div);
        }
    }

 

 

  

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------