Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Javascript function - replace ampersand with hex encoding

Posted on by 3,070

Hi guys,

I have a piece of Javascript that creates a unique URL to open a report based on the Account name, however it's failing when the name includes an Ampersand.  I have realised that I need to replace the ampersand in the name with the hex code %26 in order for it to work, but I'm not 100% on how to update my function.  For reference, the current function is below:

function OpenUrl() {
var nameAttr = parent.Xrm.Page.data.entity.attributes.get("name");
if (nameAttr !== null) {
var name = nameAttr.getValue();
var url = "myserver/.../ReportViewer.aspx;Client=" + name + "&rs%3aCommand=Render";
window.open(url);
}

Any help appreciated!

*This post is locked for comments

  • Ryan Maclean Profile Picture
    Ryan Maclean 3,070 on at
    RE: Javascript function - replace ampersand with hex encoding

    Hi Aric, the name field is just the Account Name, which is used to generate the direct link to the SSRS report.  I've tested this in my sandbox and it seems to be working fine, not sure of any potential downsides to this approach?

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Javascript function - replace ampersand with hex encoding

    What kind of data do you have in the name field? Is it just the possibility of having the & in it.

    The encodeURI might work, but the question is when you will be decoding it...

  • Verified answer
    Ryan Maclean Profile Picture
    Ryan Maclean 3,070 on at
    RE: Javascript function - replace ampersand with hex encoding

    Just to follow up on this, I think the solution might be to replace the "name" attribute in the "var url" line with encodeURIComponent(name), but I'd appreciate someone else confirming that for me

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans