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)

Dynamics CRM 365 - Encoding and Decoding Query String Parameters

(0) ShareShare
ReportReport
Posted on by

Hey everyone,

In Dynamics CRM 365 (On-Premise), I am having issues trying to pass a customer name from one entity to another and having the string get decoded correctly.

On my incident entity, I have a ribbon button that opens a custom entity and passes a customer name with the following code snippet:

var parameters = "";
  parameters += "&parameter_customerName=" + "This is a customer name with & symbol";

window.open("/main.aspx?etn=customEntity&pagetype=entityrecord&extraqs=" + encodeURIComponent(parameters), "_blank", features, false);

Now the code for the onLoad event for the custom Entity:

var parameters = Xrm.Page.context.getQueryStringParameters();
var passedCustomerName = parameters["parameter_customerName"];
alert(passedCustomerName);

var passedCustomerNameDecoded = decodeURIComponent(parameters["parameter_customerName"]);

alert(passedCustomerNameDecoded);

Both alerts are showing me the same string of text which is: This is a customer name with

However, the URL of the custom entity does have the fully encoded parameter - parameter_customerName%3DThis%20is%20a%20customer%20name%20with%20%26%20symbol

I am aware that window.open should not be used in place of Xrm.Utility.openEntityForm but I have some business requirements that I can meet with window.open such as choosing a window size.

Any suggestions would be greatly appreciated and I'm hopeful that I am simply just decoding this incorrectly.

Thank you,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi AnimalHealthCRM,

    i suspect the trick was made by Xrm.Page.context.getQueryStringParameters() which could misrepresent encoded & like an encoded parameter separator.

    The solution maybe a double encoding like the following:

    var str = "my name & your name";
    var enstr1 = encodeURIComponent(str);
    var enstr2 = encodeURIComponent(enstr1);
    alert(enstr2);
    var destr2 = decodeURIComponent(enstr2);
    var destr1 = decodeURIComponent(destr2);
    alert(destr1);

    If this solution doesnt work, your last change is to replace & character before to send querystring and restore it after retrieve, like:

    var str = "my name & your name";
    var str1 = str.replace("&","__AND__");
    var enstr1 = encodeURIComponent(str1);
    alert(enstr1);
    var destr1 = decodeURIComponent(enstr1);
    var str2 = destr1.replace("__AND__","&");
    alert(str2);

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    Instead of "encodeURIComponent()/decodeURIComponent()" use "encodeURI()/decodeURI()".  

    ** encodeURIComponent encodes the special chracters whereas encodeURI doesn't.

    www.w3schools.com/.../jsref_encodeURI.asp

    Hope this helps.

  • Community Member Profile Picture
    on at

    Francesco,

    Thank you for the solution on this one.

    Unfortunately, the first solution did not work but replacing the & symbol 'myself' using .replace worked just fine.

    This approach should work in my case because this is the only symbol I would expect to be used in this situation.

    Thanks again.

    Ravi,

    Thank you again for responding to my posts and helping me out.

    Maybe I implemented it incorrectly but using encodeURI without encodeURIComponent with window.open caused some authentication issues on my entities and I was getting invalid authorization errors when trying to launch the custom entity.

    Thanks!

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