web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript function - replace ampersand with hex encoding

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    Ryan Maclean Profile Picture
    3,070 on at

    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

  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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...

  • Ryan Maclean Profile Picture
    3,070 on at

    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?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans