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 Microsoft Employee

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 365 - Encoding and Decoding Query String Parameters

    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!

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Dynamics CRM 365 - Encoding and Decoding Query String Parameters

    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.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Dynamics CRM 365 - Encoding and Decoding Query String Parameters

    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

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,494 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans