Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions types/xrm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }
>;
}

/**
Expand Down
62 changes: 62 additions & 0 deletions types/xrm/xrm-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
);