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)

Error while retrieving data from XML file

(0) ShareShare
ReportReport
Posted on by 12,119 Moderator

Hi all

I am using below code

function ShowConfiguration() {
debugger;
var serverUrl = window.parent.Xrm.Page.context.getClientUrl();
var webResourceName = "apikey"
var webResourceURL = serverUrl + "/WebResources" + "/" + webResourceName
var nodePath = "//Configuration";
var XmlDoc= new ActiveXObject("Microsoft.XMLDOM");
XmlDoc.preserveWhiteSpace = true;
XmlDoc.async = false;
XmlDoc.load(webResourceURL);
var nodelist;
nodelist = XmlDoc.selectNodes(nodePath);
document.getElementById('APIkey').value = nodelist[0].selectSingleNode("APIkey").nodeTypedValue;
}

With the following xml file

<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<APIkey>ab15c4d132d2afuholiklhkjkl2e5a-us14</APIkey>
</Configuration>

This code giving me this 

5001.Untitled7.png

8625.Untitled6.png

 

Please tell me. Where am I wrong?

 

Thank You

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Moshe Hayun Profile Picture
    365 on at

    Hello,

    Your code seems good.

    If you add watch for nodelist[0].selectSingleNode("APIkey").nodeTypedValue, I think that you'll get your value.

    2017_2D00_02_2D00_21-10_5F00_35_5F00_49_2D00_Clipboard.png

    The error message says that "document.getElementById('APIkey')" is null, so it cannot set its value. Please make sure that you have this element APIkey (is it its real name? Not a simple copy paste from the Xml node?) on your form.

  • Verified answer
    Shidin Haridas Profile Picture
    3,497 on at

    Hi Abdul Wahab,

    Can you please verify if the HTML page on which you are running the code has an element/control named 'APIkey'?

    "document.getElementById('APIkey')' itself is null, which is why when you try to do append a '.value' to it, you are getting a null reference error.

     

    PS: I would not recommend using the ActiveX library to read the XML file, as most browsers (other than IE) does not extend support for it.

    Strongly recommend you to use jQuery library to read the XML file.

  • Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi Moshe Hayun and Shidin Haridas

    Thank You very much my friends.

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