Issues with Xrm.WebApi.retrieveMultipleRecords

Hexcode 0 Reputation points
2024-08-25T16:53:46.1066667+00:00

I am trying to display subgrid based on the value found in the form field.

for that I am using below code but unable to execute Xrm.WebApi.retrieveMultipleRecords

code:

function changeSubgridView(context) {

var formContext = context.getFormContext();

var fieldValue = formContext.getAttribute("x").getValue(); // Replace 'x' with the actual logical name of your field

console.log("Field Value: " + fieldValue);

**Xrm.WebApi.retrieveMultipleRecords("viewmappings", "?$filter=new_fieldvalue eq '" + fieldValue + "'")**.then(

    function success(result) {

        console.log("Retrieved Records: ", result.entities);

        if (result.entities.length > 0) {

            var viewMapping = result.entities[0];

            console.log("View Mapping: ", viewMapping);

            var viewToSet = {

                entityType: "contact", // Replace with the correct logical name

                id: viewMapping.viewid,

                name: viewMapping.viewname

            };

            console.log("View to Set: ", viewToSet);

            var gridContext = formContext.getControl("Contacts");

            gridContext.getViewSelector().setCurrentView(viewToSet);

            gridContext.setVisible(true);

            formContext.ui.clearFormNotification("viewNotFound");

        } else {

            console.log("No matching view found.");

            formContext.ui.setFormNotification("No matching view found for the selected option.", "ERROR", "viewNotFound");

            formContext.getControl("Contacts").setVisible(false);

        }

    },

    function error(error) {

        console.log("Error retrieving view mappings: " + error.message);

    }

);

}

while in debug mode the it doesn’t go inside the Xrm.webapi

Would appreciate your help. Thanks in advance

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
969 questions
Microsoft Copilot for Microsoft 365 Development
Microsoft Copilot for Microsoft 365 Development
Microsoft Copilot for Microsoft 365: Microsoft 365 Copilot refers collectively to Copilot experiences within Microsoft 365 applications.Development: The process of researching, productizing, and refining new or existing technologies.
114 questions
Dynamics 365 Training
Dynamics 365 Training
Dynamics 365: A Microsoft cloud-based business platform that provides customer relationship management and enterprise resource planning solutions.Training: Instruction to develop new skills.
123 questions
Microsoft Power Platform Training
Microsoft Power Platform Training
Microsoft Power Platform: An integrated set of Microsoft business intelligence services.Training: Instruction to develop new skills.
302 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.