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)

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

I have the same question (0)
  • Suggested answer
    Manju Augustine Profile Picture
    140 on at

    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.

  • Santosh Kulkarni Profile Picture
    235 on at

    Thanks Manju for reply,

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

  • HenriL Profile Picture
    485 on at

    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.

  • HarryZang Profile Picture
    240 on at

    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);

  • Suggested answer
    Pawar Pravin  Profile Picture
    5,237 on at
  • Verified answer
    HenriL Profile Picture
    485 on at

    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
    Arun Vinoth Profile Picture
    11,615 Moderator on at

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

    [View:https://stackoverflow.com/a/51525742/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

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