Cómo ejecutar la función RetrievePrincipalAccess con Xrm.WebApi
1 min de lectura
Charles Llamas
El siguiente ejemplo muestra cómo ejecutar la función RetrievePrincipalAccess.
La función obtiene los permisos o derechos de acceso (como lectura, escritura, eliminación, etc.) que un usuario o equipo (principal) tiene sobre un registro específico (target)
var Sdk = window.Sdk || {}; /** * Request to Retrieve Principal Access * @param {Object} principal - The specified security principal (team or user). * @param {Object} targetRecord - The target record for which to retrieve access rights. */ Sdk.RetrievePrincipalAccessRequest = function (principal, targetRecord) { this.entity = principal; this.Target = targetRecord; this.getMetadata = function () { return { boundParameter: "entity", parameterTypes: { "entity": { typeName: "mscrm.systemuser", structuralProperty: 5 // Entity Type }, "Target": { typeName: "mscrm.account", structuralProperty: 5 // Entity Type } }, operationType: 1, // This is a function. Use '1' for functions and '2' for CRUD operationName: "RetrievePrincipalAccess", }; }; }; var accountId = executionContext.getFormContext().getData().getEntity().getId(); var userId = Xrm.Utility.getGlobalContext().userSettings.userId; var principal = { entityType: "systemuser", id: userId }; var targetRecord = { "accountid": accountId, "@odata.type": "Microsoft.Dynamics.CRM.account" }; // Construct a request object from the metadata var retrievePrincipalAccessRequest = new Sdk.RetrievePrincipalAccessRequest(principal, targetRecord); // Use the request object to execute the function Xrm.WebApi.online.execute(retrievePrincipalAccessRequest).then( function (result) { if (result.ok) { var principalAccess = JSON.parse(result.responseText); // perform other operations as required; } }, function (error) { console.log(error.message); // handle error conditions } );