"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Sunday 20 February 2011

Reading XML file in MS Dynamics CRM 2011 using Javascript

In MS Dynamics CRM 2011, we could maintain the XML files using web resource utility, which is a very good feature. It could be read using Javascript which is also maintained in the web resources.
You could make use of this feature when you want to populate some values dynamically. So that later amendments could be done in the XML file.
The path could be in the following format after uploading the xml file into the web resources of the solution.
var xmlPath = "../WebResources/ConfigureAttributes.xml";
Sample xml file –ConfigureAttributes.xml
<attributes>
    <attribute id="DateofBirth">sol_birthdate</attribute>
    <attribute id="Name">sol_name</attribute>
</attributes>

The contents of the xml file could be read using the following code.
var nodePath = "//attributes/attribute";
var doc = new ActiveXObject("Microsoft.XMLDOM");
doc.preserveWhiteSpace = true;
doc.async = false;
doc.load(xmlPath);
params = new Array();
var nodelist;
nodelist = doc.selectNodes(nodePath);
for (var i = 0; i < nodelist.length; i++)
{
params[i] = nodelist(i).attributes[0].value;
}

2 comments:

  1. I know this works, but when you put a browse control on your web resource and let user choose a file from disk, it says Access Denied, any solution to that ?

    ReplyDelete
  2. How do you get the value (i.e. "sol_birthdate" in the above example? The params array just contains the ids?
    Any help appreciated.

    ReplyDelete