Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

HTML Webresource showing that variables are undefined

Posted on by 3,610

I've following HTML webresource, I need to get the contact id and then do rest of the stuff. It prompt me that I've 1 contact against that specific phone number but it throw exception at retreivedContact (variable in following javascript). When I go over and check the mobileNumber debugger also says that its undefined. Can you please see and let me know what is messing up the things:

<!DOCTYPE html>
<html>
<head>
    <title>Contacts</title>
	<script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
    <script type="text/javascript" src="../WebResources/new_jquery_1.9.1.min" ></script>
    <script type="text/javascript" src="../WebResources/new_xrmjson" ></script>
    <script type="text/javascript" src="../WebResources/new_xrmservicetoolkit" ></script>
    <script type="text/javascript">
        function getLoggedInUserRoles() {
            try {
                debugger;
            var context = GetGlobalContext();
            var mobileNumber = "xxx-xxx-xxx";
            if (mobileNumber.length > 0) {
                    var query = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
						"  <entity name='contact'>" +
						"    <attribute name='fullname' />" +
						"    <attribute name='telephone1' />" +
						"    <attribute name='contactid' />" +
						"    <order attribute='fullname' descending='false' />" +
						"    <filter type='and'>" +
						"      <condition attribute='mobilephone' operator='eq' value='" + mobileNumber + "'/>" +
						"    </filter>" +
						"  </entity>" +
						"</fetch>";

                    var retreivedContacts = XrmServiceToolkit.Soap.Fetch(query);

                    if (retreivedContacts.length == 1) {
						alert(retreivedContacts.length);
                        alert(retreivedContacts[0].attributes['contactid']);
                        //Xrm.Utility.openEntityForm("contact", retreivedContacts[0].attributes['contactid'])
                    }
                }
            } catch (e) {
            alert("Error: "+e.Message);
            }
    }
    </script>
</head>
<body>  
    <button onclick="getLoggedInUserRoles()">Click here</button>
</body>
</html>


*This post is locked for comments

  • Verified answer
    Mohsin Ali Profile Picture
    Mohsin Ali 3,610 on at
    RE: HTML Webresource showing that variables are undefined

    Replaced retreivedContacts[0].attributes['contactid'] with retreivedContacts[0].attributes['contactid'].value

  • Arun Vinoth Profile Picture
    Arun Vinoth 11,613 on at
    RE: HTML Webresource showing that variables are undefined

    You said it’s resolved in SO, pls post the answer & close this thread.

    stackoverflow.com/.../7920473

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans