Xrm.WebApi.retrieveMultipleRecords return error

Marco Krings 0 Reputation points
2024-06-21T10:38:29.9466667+00:00

Hello,

How can it be possible that the function rm.WebApi.retrieveMultipleRecords("teammembership", query) no longer works and throws an error when executed.

Execution in Forms Model Driven APP.

The function previously worked without any problems.


function hideTabBasedOnTeams(executionContext, tabName, teamIds) {

    var formContext = executionContext.getFormContext();

    var userId = Xrm.Utility.getGlobalContext().userSettings.userId.replace(/[{}]/g, ''); // Remove braces from userId

    // Split the comma-separated list of team IDs into an array

    var teamIdArray = teamIds.split(',');

    // Define a filter query for checking membership in any of the specified teams

    var filterQuery = teamIdArray.map(teamId => teamid eq ${teamId.trim()}).join(' or ');

    // Define the query to check team membership

    var query = /teammemberships?$filter=systemuserid eq ${userId} and (${filterQuery});

    // Retrieve records to check if the user is in any of the specified teams

    Xrm.WebApi.retrieveMultipleRecords("teammembership", query).then(

        function success(result) {

            if (result.entities.length === 0) {

                // Hide the tab if the user is not in any of the allowed teams

                formContext.ui.tabs.get(tabName).setVisible(false);

            } else {

                // Show the tab if the user is in at least one of the allowed teams

                formContext.ui.tabs.get(tabName).setVisible(true);

            }

        },

        function error(error) {

            console.error("Error checking team membership: " + error.message);

            // Optional: Display an alert to the user

            Xrm.Navigation.openAlertDialog({

                text: "An error occurred while checking team membership. Please contact your system administrator.",

                title: "Error"

            }).then(function () {

                // Hide the tab as a fallback if the check fails

                formContext.ui.tabs.get(tabName).setVisible(false);

            });

        }

    );

}


Thanks for the help.

JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
936 questions
0 comments No comments
{count} votes