g_form.getDisplayBox('reference field').value does not return values with '&'

Lathashree Ling
Kilo Contributor

I am using g_form.getDisplayBox('reference field').value in a UI action as below.

function searchCompany() {
var url = 'http://www.bing.com/search?q=';
var company = (g_form.getDisplayBox('reference_field').value);
window.open(url + company , '_blank');
}

For example, Reference field value = Apple & Pie, the URL searches just 'Apple'

However, it works fine for values with , and space. Just the '&'. Any thoughts?

 

 

1 ACCEPTED SOLUTION

Try this...

function searchCompany() {
    var url = 'http://www.bing.com/search?q=';
    var company = (g_form.getDisplayBox('u_group').value);
    company = encodeURIComponent(company).toString();
    window.open(url + company);
}

View solution in original post

12 REPLIES 12

Hi Mark,

Is g_form.getDisplayBox() a deprecated method?

How come best practice says do not get reference values directly from the client script but rather make an ajax call to get to let the server return the values?

Thank you

Miguel

Hi Miguel,

It's not deprecated. The display value is actually stored in the client so you don't need to make a server side call just to get the display value of a reference field.

If you need to get any other details on the referenced record then best practice is to use Glide Ajax rather than getReference() or a client side glide record.

Cheers

Dave 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Latha,

Can you explain your requirement here?

That could be because browser is unable to convert it into %26.

you can have once check

search for & character and replace it with %26 and it should work

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

Dubz
Mega Sage

Oops, looks like you've spelled google wrong in your URL as well 😄

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Latha,

Update your script as below and it should work fine.

function searchCompany() {
var url = 'http://www.bing.com/search?q=';
var company = (g_form.getDisplayBox('reference_field').value);

company = company.replace(/&/g, "%26");
window.open(url + company , '_blank');
}

 

Mark Correct if this solves your issue and also mark Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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