Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

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

Chuck Tomasi
Tera Patron

The underlying problem is that & is special to URLs. What you are actually telling is another parameter called Pie. You need to encode that query so & is turned in to %26. On the server side, you can do this with gs.urlEncode(). I recommend using this as a server side UI action. I don't see a big need for doing this client side.

var url = "http://yoursite.com/?search=";
var urlArg = gs.urlEncode(current.reference_field.getDisplayValue());
action.setRedirectURL(url + urlArg);

Mark Stanger
Giga Sage

You need to encode the value you're getting.  Try this...

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

Mark, this does not work!

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);
}