The following example demonstrates how to execute the RetrievePrincipalAccess function.
The function Retrieves the access rights of the specified security principal (team or user) to the specified record.
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
}
);
New Comment