Loading...

How to use parent.Xrm.WebAPI in standalone web resources (not in CRM form)

How to use parent.Xrm.WebAPI in standalone web resources (not in CRM form)
How to use parent.Xrm.WebAPI in standalone web resources (not in CRM form) taipropy001 Wed, 01/11/2023 - 11:00
Body

Are you working with CRM on-premises and developing a standalone web resources without CRM form ? You can face with this trouble and this article is for you.

What is the issue?

Basically, we need to include a reference to ClientGlobalContext.js.aspx to HTML web resources but it does not make the Xrm object available. Therefore, scripts containing Xrm.* methods aren't supported in HTML web resources. And the scripts containing parent.Xrm.* will work if the HTML web resources is loaded in a form container. However, for other places, such as loading an HTML standalone web resources, parent.Xrm.* also won't work. If you try to use it on standalone web resources in on-premise environment version 9.1 (or 9.0), you will receive the error:

Text

Description automatically generated

 

Root cause

After a lot of time to debug this error, I found it come from the Xrm.WebApi method. It is failing on a line where it attempts to take the entityname and resolve it to the setname (plural). It does this by comparing the value passed into the retrieveMultipleRecords method and comparing it to a global variable ENTITY_SET_NAMES.

This variable is unfortunately not present and parent.Xrm.WebApi throws an error.

Workaround

However, the standalone web resources is needed in some scenarios with specific business which we must accept the unsupported way to leverage the advantages of its and we could do a "magic" to use parent.Xrm.* into the standalone web resources.

Note: Please be aware that: This is the unsupported method.

First of all, we need to identify how many entities we work with parent.Xrm.WebApi in the web resource.

And those entities are not present in global variable ENTITY_SET_NAMES. So we create it.

In the window variable, we create an attribute ENTITY_SET_NAMES  is a JSON-parsable string which contains the logical name and set a name for each entity.

Finally, we need execute that function before any calls to parent.Xrm.WebApi methods appears to work.

 

Some final words

Now, your issue should be resolved. Hope that Microsoft will fix it soon and the article will become a good resource for you.

If you have any better solutions or any questions, feel free to comment below. Your opinions are appreciated.

 

Published on:

Learn more
Featured Articles | Dynamics Chronicles
Featured Articles | Dynamics Chronicles

Welcome to our blog, the content is entirely dedicated to Microsoft Dynamics 365, CRM, Power Platform, Common Data Service (CDS) but also Azure. Follow us !

Share post:

Related posts

Enhancing Knowledge Retrieval with Microsoft Copilot Agents in Dynamics CRM and SharePoint

Studies show that 70% of employees spend unnecessary time searching for information across multiple systems, leading to productivity losses an...

2 months ago

{How to} become MCT Microsoft Certified Trainer on Microsoft Dynamics 365 Customer Engagement step by step instructions

Hello Everyone,Today i am going to share guidelines on becoming Microsoft Certified Trainer on Microsoft Dynamics 365 Customer Engagement or P...

3 months ago

Default Value vs. Current Value in Dynamics 365 CE: Key Differences

In Dynamics 365 CE (Customer Engagement), environment variables are used to manage configuration settings for solutions. When dealing with env...

3 months ago

How to Write and Understand a Dynamics CRM Plugin

 Here’s a sample plugin code in Dynamics CRM written in C#, along with a detailed explanation of each line. This plugin will update the "...

4 months ago

Dynamics 365 CE Solution Import Failed in Azure DevOps Pipelines

Got the below error while importing Dynamics CRM Solution via Azure DevOps Pipeline. 2024-12-18T23:14:20.4630775Z ]2024-12-18T23:14:20.74...

4 months ago

Exploring the Differences: Managed vs. Unmanaged Solutions in Dynamics CRM/Dataverse

In Dynamics CRM/Dataverse, solutions are central to Application Lifecycle Management (ALM), providing a structured way to manage, package, and...

6 months ago

Effective Strategies for Debugging Plugins in Dynamics CRM

In a recent interview, I was asked about debugging plugins in Dynamics CRM. The interviewer specifically wanted to know my approach to plugin ...

6 months ago

Is Microsoft Dynamics CRM Affordable for Small Nonprofits?

Satish Reddy By Satish Reddy | Reading time 6 mins When considering a CRM solution, affordability is often a primary concern for small no...

9 months ago

How Microsoft Dynamics CRM Services Helps a Startup Nonprofit

Satish Reddy By Satish Reddy | Reading time 6 mins For startup nonprofits, the right Customer Relationship Management (CRM) system can be...

9 months ago

Easy Plugin Registration Tool Installation for Dynamics 365 CE Developers

Hi Folks, Are you a Power Platform or Dynamics 365 CE Developer, you would definitely need to work on Plugin Registration tool at any given po...

9 months ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy