Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

XRM.WEBAPI not working in crm solution configuration.html web resource

(0) ShareShare
ReportReport
Posted on by 235

Hi Friends,

For your understanding, I have solution and added configuration.html web resource to configuration section of  solution.

What i am trying?

Using Xrm.WeApi library to retrive and create records in dynamics crm entity.

When i execute below code i get error in script. error :""Cannot read property 'account'  of null"

======================================

Xrm.WebApi.retrieveMultipleRecords("account", "?$select=name&$top=3").then( function success(result) { for (var i = 0; i < result.entities.length; i++) { console.log(result.entities[i]); } // perform additional operations on retrieved records }, function (error) { console.log(error.message); // handle error conditions } ); 

=======================================

Also it works if my HTML resource is inside entity form but not working in solution configuration section.

did you face the same issue?Any solution? how to use xrm.webapi in this case ?

Thanks in advance.

Regards,

Santosh

*This post is locked for comments

  • Suggested answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    Basically window.opener.top.ENTITY_SET_NAMES should work like I explained in StackOverflow.

    [View:https://stackoverflow.com/a/51525742/7920473]

  • Verified answer
    HenriL Profile Picture
    485 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    My colleague participated in that thread of stackoverflow. I am using his workaround for now that I think its simple and easy, until Microsoft fixes the issue.

    Basically, the webapi looks for constants that are retrieved by one of CRM main webpages. Simply supplying the constants will allow the Xrm.WebApi to work.

    For each entity:

    a. specifies its Set Name, eg. account = accounts, contact = contacts, new_custom = new_customs

    b. specifies its Primary Key, eg. account = accountid, contact = contactid, new_custom = new_customid

    function prepareCrmConstants() {

           window["ENTITY_SET_NAMES"] = window["ENTITY_SET_NAMES"] || JSON.stringify({

               "contact": "contacts"

           });

           window["ENTITY_PRIMARY_KEYS"] = window["ENTITY_PRIMARY_KEYS"] || JSON.stringify({

               "contact": "contactid",

           });

       };

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    Hi Santosh,

    Please do refer following urls:

    www.toplinestrategies.com/.../crm-rest-builder-useful-tool-working-crm-2016%E2%80%99s-web-api

    stackoverflow.com/.../using-xrm-webapi-method-in-web-resource-opened-in-a-new-window

  • HarryZang Profile Picture
    240 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    I am facing the same issue before:

    https://community.dynamics.com/crm/f/117/t/283353

    The parent.Xrm trick also does not work 

    Instead, I have to use the httprequest code.

    something like:

    var query = "EntityDefinitions?$select=ObjectTypeCode&$filter=LogicalName eq '" + eName + "'";
    var req = new XMLHttpRequest();
    req.open("GET", Util.getWebAPIEndpoint() + query, false);

    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.send();
    var object = JSON.parse(req.responseText);

  • HenriL Profile Picture
    485 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    Yep, I am getting the same error. The Xrm.WebApi library is not working on custom HTML webresource, but works on entity Forms only (at least). Its either a bug or the CRM Dev team hasn't implemented it yet.

  • Santosh Kulkarni Profile Picture
    235 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    Thanks Manju for reply,

    I tried using parent.XRM, but same error...

  • Suggested answer
    Manju Augustine Profile Picture
    140 on at
    RE: XRM.WEBAPI not working in crm solution configuration.html web resource

    Hi,

    Can you please debug the code and check if Xrm is defined or not when you call it from the Configuration Page. If Xrm is not defined, try using parent.Xrm.

    Thanks,

    Manju Augustine.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans