Html and Xml Encoding/ Decoding in Dynamics 365/ CDS Client API

If you are looking for html encoding/ decoding  while writing client code in Dynamics 365/ CDS, you don’t need to look to any jQuery or third party libraries to do that. Infact Dynamics 365 Client API have Xrm.Encoding namespace which contains all the method to perform html encoding/ decoding and xml encoding/ decoding as well.

HTML Encoding– Xrm.Encoding.htmlEncode(<string value>);

HTML Decoding – Xrm.Encoding.htmlDecode(<string value>);

Xml Encoding – Xrm.Encoding.xmlEncode(<string value>);

Xml Decoding – Xrm.Encoding.xmlDecode(<string value>);

Please note that encoding may differ from the expected. For example, a normal HTML encode for the string – “<Test>” would yield “&lt;Test&gt;”. However the same when used with Xrm.Encoding.htmlEncode shall yield – “<test>”

Hope this tip helps!

Debajit Dutta

(Business Solutions MVP)