How to create a link in popup using client script in Service Portal

Hiranmayee Moha
Tera Expert

Hi @ Ankur Bawaskar!

If the user selects 'Yes' from choice list of a catalog item, a popup will show with a link that says, Please raise a request to "XYZ Software".

 

The code is attached below:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
 
   var yes = g_form.getValue('variable');
 
 if (yes) {
    var Url = 'link';
 
g_form.addInfoMessage("Please raise a request to 'xyz Software' in the catalog: <a href='" + Url + "'</a>");
 
    }
}
 
TIA
Hiranmayee Mohanta

 

4 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Hiranmayee Moha 

something like this will show link in portal

Ensure you give correct URL

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var yes = g_form.getValue('variableName'); // give the variable name here
    if (yes == 'yes') { // give the value you want to compare
        var urlString = '<p><a class="web" target="_blank" href="' + "/esc" + '">' + "Click Here" + '</a></p>';
        g_form.addInfoMessage("Please raise a request to 'xyz Software' in the catalog:" + urlString);
    }
}

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

View solution in original post

SumanthDosapati
Mega Sage
Mega Sage

@Hiranmayee Moha 

Try below approach

var link = '<a href="google.com">URL</a>';
var message = 'Please raise a request to xyz software in the catalog' + ' ' + link + ' ';
gs.addInfoMessage(message);

Accept the solution and mark as helpful if it does, to benefit future readers.
Regards,
Sumanth

View solution in original post

@Hiranmayee Moha 

My mistake, gs wont work in client scripts.

use g_form.addInfoMessage.

 

 

View solution in original post

Hi @Ankur Bawiskar !

 

It worked. I had done a small mistake.

 

Thanks again

Hiranmayee Mohanta

View solution in original post

18 REPLIES 18

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Hiranmayee Moha 

 

You need to use GlideModal for this requirement.

 

Thanks and regards

Sai Venkatesh

Ankur Bawiskar
Tera Patron
Tera Patron

@Hiranmayee Moha 

something like this will show link in portal

Ensure you give correct URL

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var yes = g_form.getValue('variableName'); // give the variable name here
    if (yes == 'yes') { // give the value you want to compare
        var urlString = '<p><a class="web" target="_blank" href="' + "/esc" + '">' + "Click Here" + '</a></p>';
        g_form.addInfoMessage("Please raise a request to 'xyz Software' in the catalog:" + urlString);
    }
}

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

Hi @Ankur Bawiskar !

 

Thanks for your quick reply. The below code is not working.

var test = g_form.getValue ('type_of_activity');
 if (test == 'Yes') {
 var urlString = '<p><a class="web" target="_blank" href="' + "/esc" + '">' + "google.com" + '</a></p>';
var message = ('Please raise a request to xyz software in the catalog' + urlString);
}
Thanks

Hi @Ankur Bawiskar !

 

var test = g_form.getValue ('type_of_activity');
 if (test == 'Yes') {
 var urlString = '<p><a class="web" target="_blank" href="' + "/esc" + '">' + "google.com" + '</a></p>';
var message = ('Please raise a request to xyz software in the catalog' + urlString);
g_form.addInfoMessage(message);
}