Turkish character problem in URLs in CRM 2013

Hi everyone,
In this article, I am gonna talk about the Turkish character problem in CRM forms when we type Turkish characters in the passed parameter values in URLs.
For those who has not known yet, these are the characters that are specific to Turkish language:

ç, Ç, ğ, Ğ, ı, İ, ö, Ö, ş, Ş, ü, Ü

It is very annoying to see Turkish characters as distorted in CRM especially if you are using CRM in Turkish.
So, here is an example about it;

Note: You can use Form String Parameter Tool Managed Solution to get URL to set default values into the CRM forms. The tool can be downloaded here

The tool automatically encodes non-english characters which is also valid for Turkish character. But this is just for testing. I was using hard coded urls so nobody does URL encoding in there for you. Here comes this article to your help 🙂

The example below sets the default profession name with the given value to the URL.

When we type

https://YourCrmUrl.com/main.aspx?etn=vrp_profession&pagetype=entityrecord&extraqs=formid%3DTheFormIdGoesHere%26

vrp_professionname%3DKürkçü Dükkanı#116843951

(red marked characters are Turkish characters in URL)

in our browser we will see a window like below:

 

Turkish character problem in Profession in CRM

 

 

You see? While I want it to be written as Kürkçü Dükkanı it showed me something very distorted like K�rk�� D�kkan?

In my case I needed to replace those distorted Turkish specific characters when I was working with a web service.
To handle this problem I wrote below script in C# and then get the refined value and used it.
As you can see this method takes the Turkish text to be encoded (or refined) and returns the URL friendly form of it.

///
/// Function for encoding Turkish characters in url
///
public static string GetEncodedUrlForTurkishCharacters(string textToEncode) {
	string temp = textToEncode;

	for (int i = 0; i < temp.Length; i++) {
		if (temp[i] == 'ç') {
			temp = temp.Replace("ç", "%C3%A7");
		} else if (temp[i] == 'Ç') {
			temp = temp.Replace("Ç", "%C3%87");
		} else if (temp[i] == 'ğ') {
			temp = temp.Replace("ğ", "%C4%9F");
		} else if (temp[i] == 'Ğ') {
			temp = temp.Replace("Ğ", "%C4%9E");
		} else if (temp[i] == 'ı') {
			temp = temp.Replace("ı", "%C4%B1");
		} else if (temp[i] == 'İ') {
			temp = temp.Replace("İ", "%C4%B0");
		} else if (temp[i] == 'ö') {
			temp = temp.Replace("ö", "%C3%B6");
		} else if (temp[i] == 'Ö') {
			temp = temp.Replace("Ö", "%C3%96");
		} else if (temp[i] == 'ş') {
			temp = temp.Replace("ş", "%C5%9F");
		} else if (temp[i] == 'Ş') {
			temp = temp.Replace("Ş", "%C5%9E");
		} else if (temp[i] == 'ü') {
			temp = temp.Replace("ü", "%C3%BC");
		} else if (temp[i] == 'Ü') {
			temp = temp.Replace("Ü", "%C3%9C");
		}
	}

	return temp;
}

 

After beautifying your url should be like this:

https://YourCrmUrl.com/main.aspx?etn=vrp_profession&pagetype=entityrecord&extraqs=formid%3DTheFormIdGoesHere%26

vrp_professionname%3DK%C3%BCrk%C3%A7%C3%BC%20D%C3%BCkkan%C4%B1

(red marked characters are encoded version of Kürkçü Dükkanı text URL)

And you can see the successful result as below picture:

 

Turkish character problem in Profession has been solved

 

 

Important Update:

I was not aware of UrlEncode Method in C# when I wrote this post. You can also use UrlEncode method instead of writing a method like I did before. For a detailed explanation; you can refer to the HttpUtility.UrlEncode Method in MSDN page.

If you are working with javascript, it also has a function named encodeURIComponent to encode URLs. For a detailed explanation; you can refer to the JavaScript encodeURIComponent() Function in w3schools page.

 

I hope that you find this article useful!
Happy coding! 🙂

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *