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 :
Customer experience | Sales, Customer Insights,...
Unanswered

Unable to retireve records Xrm.WebApi.retrieveMultiplerecords

(1) ShareShare
ReportReport
Posted on by 7
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

 

I have the same question (0)
  • Ray Profile Picture
    1,537 on at
    Did you get any error message? You can set a breakpoint in both success and error callback method.
  • Sid_Works Profile Picture
    7 on at
    It's not going inside the Xrm.WebApi.retirvemultiplerecords and not even going to error block. 
     
     
  • Ray Profile Picture
    1,537 on at
    As it is not going inside the Xrm.WebApi. I think the code get error before this call. You can try to debug your code line by line. I think there might be two possible reason: 1. context parameter is not passed correctly; 2. the field is not put on the form so getValue() throw a exception.

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 72 Super User 2025 Season 2

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

#3
Gerardo RenterĂ­a GarcĂ­a Profile Picture

Gerardo RenterĂ­a Ga... 29 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans