diff --git a/types/xrm/index.d.ts b/types/xrm/index.d.ts index 6dd01bbadbe084..181d57bdc6dca0 100644 --- a/types/xrm/index.d.ts +++ b/types/xrm/index.d.ts @@ -321,6 +321,24 @@ declare namespace Xrm { * Returns the difference in minutes between the local time and Coordinated Universal Time (UTC). */ getTimeZoneOffsetMinutes(): number; + /** + * Returns a promise resolving to an object whose properties are the privilege GUIDs and whose values are privilege info objects for each security role privilege assigned to the user. + * @see {@link https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/xrm-utility/getglobalcontext/usersettings#getsecurityroleprivilegesinfo-method Microsoft Docs: getSecurityRolePrivilegesInfo} + * + * @param successCallback Optional. A callback function to execute when the operation is successful. + * @param errorCallback Optional. A callback function to execute if the operation fails. + * @returns A promise that resolves to a dictionary where each key is a privilege GUID and value is an object with privilege details. + */ + getSecurityRolePrivilegesInfo( + successCallback?: ( + result: { + [privilegeId: string]: { id: string; businessUnitId: string; privilegeName: string; depth: number }; + }, + ) => void, + errorCallback?: (error: { errorCode: number; message: string }) => void, + ): Promise< + { [privilegeId: string]: { id: string; businessUnitId: string; privilegeName: string; depth: number } } + >; } /** diff --git a/types/xrm/xrm-tests.ts b/types/xrm/xrm-tests.ts index 5aa6c99491c672..45093b2332dd7d 100644 --- a/types/xrm/xrm-tests.ts +++ b/types/xrm/xrm-tests.ts @@ -884,3 +884,65 @@ Xrm.WebApi.offline.isAvailableOffline(12345); // Should error with extra parameters // @ts-expect-error Xrm.WebApi.offline.isAvailableOffline("account", "extra"); + +// Demonstrate userSettings.getSecurityRolePrivilegesInfo().then(successCallback, errorCallback) + +const context = Xrm.Utility.getGlobalContext(); + +// $ExpectType Promise<{ [privilegeId: string]: { id: string; businessUnitId: string; privilegeName: string; depth: number } }> +const privilegePromise = context.userSettings.getSecurityRolePrivilegesInfo(); + +privilegePromise.then(result => { + // $ExpectType { [privilegeId: string]: { id: string; businessUnitId: string; privilegeName: string; depth: number } } + result; + + Object.keys(result).forEach(privilegeId => { + const privilege = result[privilegeId]; + + // $ExpectType string + privilege.id; + + // $ExpectType string + privilege.businessUnitId; + + // $ExpectType string + privilege.privilegeName; + + // $ExpectType number + privilege.depth; + }); +}); + +// Test the successCallback and errorCallback parameter types. +context.userSettings.getSecurityRolePrivilegesInfo( + result => { + // $ExpectType { [privilegeId: string]: { id: string; businessUnitId: string; privilegeName: string; depth: number } } + result; + + Object.keys(result).forEach(privilegeId => { + const privilege = result[privilegeId]; + + // $ExpectType string + privilege.id; + + // $ExpectType string + privilege.businessUnitId; + + // $ExpectType string + privilege.privilegeName; + + // $ExpectType number + privilege.depth; + }); + }, + error => { + // $ExpectType { errorCode: number; message: string } + error; + + // $ExpectType number + error.errorCode; + + // $ExpectType string + error.message; + }, +);