From bf940f41b423425c4f87cff375a4ab94daba3539 Mon Sep 17 00:00:00 2001 From: Adam Naji <110662505+Bashamega@users.noreply.github.com> Date: Sat, 29 Aug 2026 05:35:51 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#75454=20Add=20getS?= =?UTF-8?q?ecurityRolePrivilegesInfo=20method=20to=20userSettings=20by=20@?= =?UTF-8?q?Bashamega?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bashamega --- types/xrm/index.d.ts | 18 ++++++++++++ types/xrm/xrm-tests.ts | 62 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) 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; + }, +);