JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
969 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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