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

How to add the hyperlink in the portal

PRAGHATIESH S
Tera Expert

Hi,

I written one script include and call that into client script to show the field msg. In that message box itself I have to add the hyperlink of url. That url is stored in the one field called "contactlink". 

 

How to add the hyperlink in the client to show on the portal.

6 REPLIES 6

SP22
Giga Sage

Hi @PRAGHATIESH S ,
Could you please have a look at the sample script below and let me know if it is useful

function onLoad() {
    var ga = new GlideAjax('GetPurchaseRequestDetails');
    ga.addParam('sysparm_name', 'getPurchaseRequest');
    ga.addParam('sysparm_external', g_form.getUniqueValue());
    ga.getXMLAnswer(function(response) {
        var res = JSON.parse(response);
        if (res.conditionMet == true || res.conditionMet == "true") {
            var contactLink = res.contactLink;
            // Create a clickable hyperlink
            var fieldMsg = "The total amount of your request exceeds €250k, therefore your request must be handled in the S2C process.<br>";
            fieldMsg += '<a href="' + contactLink + '" target="_blank">Contact Person</a>';
            g_form.showFieldMsg('u_total_of_esr_request_eur_incl_changes', fieldMsg, 'info');
        } else {
            g_form.hideFieldMsg('u_total_of_esr_request_eur_incl_changes', true);
        }
    });
}


Thanks
Santosh.P

You will have to create a hyper link in a tag like below:

“<a href=“ +contactlink +”>Link<a>”


Raghav
MVP 2023
LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

@PRAGHATIESH S 

showFieldMsg() doesn't support HTML tags and hence you cannot show link there using that function.

Workaround

1) create Rich Text Label variable and store the static link there and always hide this variable using UI policy

2) then from your client script show/hide this above variable and show link

OR
1) If your link is dynamic then create a widget and add it to variable of type Custom

2) then in that widget observe the change of variable and do GlideAjax there and show the link in the widget HTML section

Service Portal Widget - grabbing variable value on change in Client Script and passing to Server Scr... 

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@PRAGHATIESH S 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

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