Microsoft Dynamics – querying User Roles using SQL

Recently we had a requirement to check who had a certain privilege across all of our Dynamics environments. The privilege in question was ‘Delete Change History‘ for Audit History records.

The ‘Delete Change History‘ role is found under Miscellaneous privileges, and the internal name is prvDeleteRecordChangeHistory. A full list of these can also be found on Microsoft Learn.

We need to find all of the Security Roles where this was enabled, and then the users who had this role. The interface to roles and privileges works but does not allow the searching we require.

SQL 4 CDS comes to the rescue yet again. I won’t go over the install procedure, but basically go to XrmToolBox, then download the SQL 4 CDS plugin.

Once it’s installed and you’ve connected to your Dynamics environment you can query the appropriate tables. There are several tables that hold the required information:
• systemuser
• role
• privilege
• roleprivileges

See examples below

Show all the users who have a specific privelege

SELECT
   systemuser.fullname AS UserName,
   systemuser.domainname,
   role.name AS RoleName,
   privilege.name AS PrivilegeName,
   privilege.accessright
FROM
   systemuserroles
JOIN
   systemuser ON systemuserroles.systemuserid = systemuser.systemuserid
JOIN
   role ON systemuserroles.roleid = role.roleid
JOIN
   roleprivileges ON role.roleid = roleprivileges.roleid
JOIN
   privilege ON roleprivileges.privilegeid = privilege.privilegeid
WHERE
   privilege.name = 'prvDeleteRecordChangeHistory'
ORDER BY
   systemuser.fullname, role.name

Users who have System Administrator role

SELECT
   systemuser.fullname AS UserName,
   systemuser.domainname,
   role.name AS RoleName,
   accessmodename,*
FROM
   systemuserroles
JOIN
   systemuser ON systemuserroles.systemuserid = systemuser.systemuserid
JOIN
   role ON systemuserroles.roleid = role.roleid
WHERE
   role.name = 'System Administrator' and azurestatename = 'Exists' and accessmodename <> 'Non-interactive' and isdisabled=0
ORDER BY
   systemuser.fullname, role.name

Hope this helps. 🙂

Dynamics Workflows Primary Entities

The Microsoft Dynamics Advanced Settings pages have been around for as long as I can remember – probably since Dynamics CRM 2011.

It’s been marked as deprecated for a number of years – but not totally gone yet. It used to be accessible from the top-right cog, and then ‘Advanced Settings’, but since Release Wave 2 this now takes you to the Power Platform Environment Settings

The issue is that some functionality isn’t available in the updated interface.

A prime example I found recently, is that viewing Processes in a Solution differs from the old and new interface.
The new interface (make.powerapps.com) shows Processes as below:

Which looks fine until you have many workflows and want to see the Primary Entity of a workflow.

See the older interface:

So why has this been removed from the new interface. Presumably there’s a reason for this.

Anyway, for now, we can still access the old interface by using the below URL

YOURORG.crm4.dynamics.com/main.aspx?settingsonly=true

That’ all for now 😀

Microsoft Dynamics – Users Last Logged In Date/Time

Table of Contents:

  1. Introduction
  2. Enabling User Auditing
  3. Method 1: Using “XrmToolBox” and “Get Last Login for Users”
  4. Method 2: Using “XrmToolBox” and “SQL 4 CDS”
    1. Download and Open spreadsheet
    2. Install and configure SQL 4 CDS
    3. Get Active Users
    4. Get Last Logged In Values
    5. Final Results

Introduction

Recently, we wanted to carry out a Dynamics license clean-up exercise, and remove any users who had not used the system for a few months. We wanted to create an export with enabled users, and when they last logged in to Dynamics.

Enabling User Auditing

Data regarding the users last login date is only stored if “Log Access” is enabled. I recommend switching this on for all of your environments.

Go to Power Platform Admin Center

Click on the environment

Under Auditing, click on Manage

Enabled ‘Start Auditing’ and ‘Log Access’

Click Save

Method 1: Using “XrmToolBox” and “Get Last Login for Users”

If you have less than 500 users you can use the excellent tool ‘Get Last Login for Users‘, which runs in the also excellent XrmToolBox.

It is very easy to use:

  1. Download and run XrmToolBox
  2. Create a connection to your Dynamics environment
  3. Install the tool ‘Get Last Logged in time for CRM Users‘, and connect to your Dynamics environment
  4. Click the button ‘Get all Users Logins
  5. Click the Excel button to export

Method 2: Using “XrmToolBox” and “SQL 4 CDS”

If, as in my case, you have more than 500 users you can export data to excel, and manipulate the data to show all users, and when they last logged in.

Download and Open spreadsheet

Install and configure SQL 4 CDS

  1. Download and run XrmToolBox
  2. Create a connection to your Dynamics environment
  3. Install the tool ‘SQL 4 CDS‘, and connect to your Dynamics environment
  4. You should now have something similar to the below

Get Active Users

Paste in the below SQL, which returns all active interactive users, excluding internal user accounts.
Press F5 to execute the query.

SELECT systemuserid, domainname, fullname FROM systemuser
WHERE isdisabled = 0 AND accessmode = 0

Select the results grid, press CTRL + A to select all, then right-click on the grid, and click ‘Copy

In the spreadsheet, in the tab ‘Active Users‘ paste the results into cell A2

Currently the column ‘Last Logged In” will show as #N/A. This is because we have not yet completed the process.

Get Last Logged In Values

Select all of column E by click on the header

Press Ctrl + C to copy these values

In XrmToolBox clear the current SQL, and then click in the SQL area, and then press CTRL + V to paste in the new SQL.
Press F5 to execute the query. This may take several minutes to run.
You should see similar to below:

Select the results grid, press CTRL + A to select all, then right-click on the grid, and click ‘Copy‘.

In the spreadsheet, in the tab ‘Login SQL Output‘ paste the results into cell A2

Final Results

In the spreadsheet, the tab ‘Active Users‘ will now show the users, and when they last logged in:

I hope you find this useful 😊

Notion Highlight Colours

I’ve recently starting using Notion for some of my digital notes. As a long time Evernote user I find the notes in Notion easier to visualise as they are stored in a hierarchical format. Evernote uses a tagging system which is more flexible but can be quite confusing.

One thing I don’t like about Notion is that the colour options for highlighting text only have pastel/neutral colours

Last year Trello changed their colours from “normal” colours to more neutral colours – which caused a bit of backlash with their users.

Anyway, in Notion there is a way to add a highlight with any colour, using the equation feature. The process is, to add the below text first

\colorbox{#55FF55}{\color{#000000} \text{TEXT} }

Then right click on it, and choose “Create Equation”

In the next dialog, edit the TEXT to whatever you want, then select Done

And there you have it – nicely visible highlighted text.

You can edit the value 55FF55 after \colorbox to get different colours. Some options are:

Yellow – FFFF00
Red – FFAAAA
Blue – 88FFFF

Also, you can choose your own colour using htmlcolourcodes.com. Just select your colour and copy the HEX value.

The downside with this method is that the whole line is highlighted, so you can’t have mixed text and highlighted text on the same line.

I think Notion will be updated at some point to include brighter highlight colours, but this seems to be the only option for now.

Photo by Robert Katzki on Unsplash

Kefalonia 2022

We had booked to go to Kefalonia with TUI in May 2020, but that didn’t go ahead, so we rebooked and went in June this year. We stayed at the Apollonion Resort & Spa, which was a very luxurious hotel but ultimately a bit far out from the main island than we would have liked.

The Hotel Location

There is a car/person ferry which goes every 30 mins from Lixouri to Argostoli which saves the 30-45 min drive around the coast

The hotel itself was very nice – parking outside our front door, and a very quiet balcony.

There seems to be a shortage of hire cars in many places, and there was no exception here. I did find someone through Facebook who provide excellent service – https://www.facebook.com/acerentacarkefalonia.

There are a large number of beaches to explore on Kefalonia – here are a few of them:

Of course there was the obligatory 1 day scooter rental (rented from http://motoround-kefalonia.gr/en/). There are some excellent remote spots to see around the island.

The Scooter (Aeon Elite 350cc)

This is the route I took. I started from Argostoli, headed South, past Skala, then back up the East Coast, before heading South West back to Argosoli.

Finally, a selection of photos from the week.

General thoughts put onto screen