In this scenario, it seems like the user is still referenced in the Project Team records within Dynamics 365, even though their account has been removed from Entra ID. Since you're unable to delete the user from the msdyn_projectteam table directly, here are some steps you can follow to resolve this issue:
1. Check for the User in Project Team Records
Even though the user does not appear in the project in project.microsoft.com, the user might still be referenced in the msdyn_projectteam records in Dynamics 365. You need to check all the project teams where the user might still be associated, which could be done using a query or advanced find:
Use Advanced Find in Dynamics 365 to search for records in the msdyn_projectteam entity where the Bookable Resource is still referencing the deleted user.
Filter by the Bookable Resource field and search for any records where the user’s ID or name still appears.
2. Manually Remove the User from Project Teams
If you find project teams that reference the deleted user, you can manually update or delete the msdyn_projectteam records:
Navigate to the Project Team: In Dynamics 365, go to the project record, find the Project Team subgrid, and manually remove the user from any associated teams.
Direct Update in the UI: If the project team is still visible in the UI, go to the Project Team section within each project and manually remove the user from each team.
3. Use Data Import/Export to Delete or Update Records
If manually removing the user from the UI is not practical due to the volume of records, you can consider using a data export/import approach:
Export Project Team Data: Export the msdyn_projectteam data to Excel (or use the Data Export Service) and remove the rows where the deleted user is still present.
Re-import the Data: After making the necessary adjustments in the exported file, re-import the corrected data into Dynamics 365 to update the msdyn_projectteam table.
4. Use Power Automate or Custom Workflow
If the above manual methods are not feasible, you can create a Power Automate Flow or a custom workflow to:
Identify and remove the user from all msdyn_projectteam records that are still referencing them.
The flow or workflow could be triggered on a scheduled basis or whenever a user is removed from the system, ensuring no orphaned records remain.
5. Check for User References in Other Tables
The user might also be referenced in other tables, such as bookableresource, workassignments, or project tasks. Make sure you check the Bookable Resource and other related tables to ensure there are no lingering references:
Use Advanced Find to search for the user in these tables.
Remove or update references as necessary.
6. Use the Web API to Clear References Programmatically
If you're comfortable working with code, you can use the Dynamics 365 Web API to programmatically search and delete or update any references to the user in the msdyn_projectteam or related entities:
Retrieve all project team records that reference the user.
Update or delete the relevant records via the Web API.
Example query using Web API:
GET [Organization URI]/api/data/v9.1/msdyn_projectteams?$filter=bookableresourceid eq [User's GUID]
Then, use a DELETE or PATCH request to clean up the records.