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

@poornima batchu 

in the above image it's working in native.

Are you checking in portal? Possibly it won't work there due to DOM manipulation.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Needing to use this in Service Portal would have been excellent information to have at the outset - along with needing it conditionally, and on a Catalog Item variable as opposed to a table field,.........

One alternative that works in both interfaces is to create a variable with the type Rich Text Label (which should sound like a familiar suggestion), then use a simple, administration beginner's-level Catalog UI Policy to hide it unless another variable's value is whatever your requirement is

 

BradBowman_2-1701977865927.png

 

 

BradBowman_1-1701977832264.png

 

Thank you so much I have used rich text variable.

Great solution! I applied that for the same purpose in my personal DEV instance. I struggled for a bit since I was using the inner HTML code within an AJAX function. I just removed the "this" keyword and it worked perfectly.

 

Much appreciated!

 
 

 

function onChange(control, oldValue, newValue, isLoading) {
        if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below

    newValue = g_form.getValue('kb_article'); //Value from field on a form

    var base_uri = new GlideAjax('kbUri'); //script include to get base instance URL ('glide.servlet.uri' ) in the client script
    base_uri.addParam('sysparm_name', 'kburl');
    base_uri.getXML(GetUri);

    function GetUri(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        var uri = answer + "kb_view.do?sysparm_article=" + newValue;
        var urlUri = '<div><a class="web" target="_blank" href="' + uri + '">' + newValue + '</a></div>';
        var msg = ('Click on the link below to see the KB article in a new tab.' + urlUri);

        var str;
        var placeholder = "##placeholder##";
        g_form.showFieldMsg('sub_category', placeholder, 'info', false);
        str = document.getElementsByClassName("fieldmsg notification notification-info")[0].innerHTML;
        str = str.substring(0, str.indexOf(placeholder));
        document.getElementsByClassName('fieldmsg notification notification-info')[0].innerHTML = str + msg;

    }

 

 

Sagar Pagar
Tera Patron

Hi @poornima batchu,

 

Yes. This is limitations for g_form.showFieldMsg.

 

You can use the Rich Text Label variable type and include the URL.

Types of service catalog variables 

 

 

If my response helps you resolve your issue. Kindly mark it as helpful & correct. It will be helpful to future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow