web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Import Legacy Users to Online

(3) ShareShare
ReportReport
Posted on by 8

I am trying to migrate Legacy (Inactive) users from a on-prem Dynamics CRM to Power Platform. The import I used comes with this error "Statement conflicted with a constraint. The INSERT statement conflicted with the FOREIGN KEY constraint "system_user_roles". The conflict occurred in database "db_xxxxxxxxxx_xxxxxxxx_xxxxxxxx_fcdc", table "dbo.SystemUserBase", column 'SystemUserId'. The statement has been terminated."

I do understand that these users will be Stub users (as these users are no longer with the company), also I understand that the SalesPerson security Roles gets added automatically. I DO NOT have that role as I am not using the Dynamic Apps in online environment.

What would be a solution to get these users imported?

I have the same question (0)
  • Suggested answer
    Holly Huffman Profile Picture
    6,538 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening :) depending on your location!
     
    The error you're encountering during the migration of legacy (inactive) users to the Power Platform is related to the FOREIGN KEY constraint tied to the system_user_roles table. This happens because stub users are automatically assigned the SalesPerson security role during the import process, and the system expects this role to exist in the target environment. Since you're not using Dynamics Apps in the online environment, the absence of this role is causing the conflict.
     
    Steps to Resolve the Issue:
    1. Create the SalesPerson Security Role Temporarily:
      • In your online environment, create a SalesPerson security role with minimal permissions.
      • This will satisfy the system's requirement during the import process.
      • After the import is complete, you can delete or modify this role as needed.
    2. Modify the Import File:
      • If possible, modify the import file to exclude the system_user_roles mapping for these stub users. This may require using a tool like SSIS with KingswaySoft or a custom script to preprocess the data.
    3. Use a Custom Security Role:
      • Instead of relying on the default SalesPerson role, create a custom security role with the necessary permissions for stub users.
      • Update the import process to map stub users to this custom role instead.
    4. Manually Assign Roles Post-Import:
      • If the import tool allows, skip the role assignment during the import process.
      • After the users are imported, manually assign them a minimal security role to ensure compliance.
    5. Check for Missing Dependencies:
      • Ensure that all dependencies (e.g., roles, teams, and business units) for the stub users exist in the target environment before starting the import.
    6. Use the SDK or API for Import:
      • Stub users can be created using the Create Request method of the SDK or API. This approach gives you more control over the import process and avoids conflicts with default role assignments.
     
     
    Hope this helps!
  • RS-08041850-0 Profile Picture
    8 on at
    Holly Thank you for your reply, So i am using an ETL tool (Scribe) that is moving these users to the online environment. But I am still receiving that Foreign key error in the ETL tool. I am not mapping anything for the security roles in this script. There was someone that I work with changed something in my environment to allow the creation of stub users but i need to do this in other environments as well. That person hasn't told me what they did and i asked multiple times with now answer.
     
    Is there a setting or something in the Power Platform environment that needs to be changed?
  • Verified answer
    Daivat Vartak (v-9davar) Profile Picture
    7,835 Super User 2025 Season 2 on at
    Hello RS-08041850-0,
     

    The error message "Statement conflicted with a constraint. The INSERT statement conflicted with the FOREIGN KEY constraint 'system_user_roles'. The conflict occurred in database 'db_xxxxxxxxxx_xxxxxxxx_xxxxxxxx_fcdc', table 'dbo.SystemUserBase', column 'SystemUserId'. The statement has been terminated." clearly indicates that you're trying to insert records into the SystemUserBase table (which represents users) without the necessary corresponding entries in the SystemUserRoles table.

     

    Here's a breakdown of the issue and potential solutions, considering you're dealing with legacy (inactive) users and using an ETL tool (Scribe):

    Understanding the Foreign Key Constraint:

    The system_user_roles foreign key constraint enforces the relationship between the SystemUserBase table and the RoleBase table (security roles) through the SystemUserRoles intersection table. For every user (SystemUserId) in SystemUserBase, there must be at least one corresponding entry in SystemUserRoles linking that user to one or more security roles.

     

    Why You're Getting the Error:

    When you're importing users, even inactive "stub" users, the system still expects them to be associated with at least one security role. The automatic addition of the "SalesPerson" role you mentioned is a standard behavior in Dynamics 365 Sales environments. Since you're not using Dynamics 365 Apps in your online environment, this automatic role assignment isn't happening.

     

    Solutions to Import Legacy (Inactive) Users:

    Here are several approaches you can take to resolve this foreign key constraint issue:

    1. Map a Default Security Role in Your Scribe ETL:

    This is the most straightforward and recommended approach.

    • Identify a Suitable Default Role: Choose a security role in your Power Platform environment that can be assigned to these legacy inactive users. This could be a custom role specifically created for inactive users with minimal privileges, or even a standard role like "Basic User" if it doesn't grant unintended access.

    • Map the Role During ETL: In your Scribe ETL process, you need to explicitly map a value for the security role(s) for the users being imported. This will likely involve:

      • Looking up the RoleId: You'll need to query the RoleBase table in your target Power Platform environment to get the RoleId (GUID) of the default role you've chosen.

      • Creating SystemUserRoles records: Your ETL process needs to insert records into the SystemUserRoles table. Each record in this table requires:

        • SystemUserId (the SystemUserId of the user you are importing).

        • RoleId (the GUID of the default security role you looked up).

        • SystemUserRoleId (a unique GUID for the entry in SystemUserRoles).

        • VersionNumber. 
         

    • Modify Your Scribe Script: Update your Scribe script to include the logic for looking up the RoleId and inserting the corresponding records into SystemUserRoles during the user import process.

    •  

    2. Create a "Stub User" Security Role (Recommended):

    This provides a cleaner separation for your legacy users.

    • Create a New Security Role: In your Power Platform environment, create a new security role specifically for these inactive "stub" users. Give it a clear name like "Legacy Inactive User" or "Stub User." Grant this role minimal to no privileges.

    • Follow Solution 1: Map this newly created "Stub User" role in your Scribe ETL process.

    •  

    3. Temporarily Allow Creation of Users Without Roles (Less Recommended):

    This involves potentially bypassing the foreign key constraint, which can have unintended consequences and might not be easily achievable or recommended in a production environment. It's likely the "something" your colleague did involved a temporary configuration change at the database level, which is generally discouraged and unsupported.

    • Database-Level Changes (Highly Risky): Directly altering database constraints should be avoided unless you have a deep understanding of the underlying schema and potential impacts. This could lead to data inconsistencies and is not a supported customization method for Power Platform.

    • Code-Based Bypass (Complex and Potentially Unsupported): You might theoretically be able to write custom code (e.g., a plugin) that triggers before the user creation to temporarily associate a default role if none is provided in the import. However, this adds complexity and might not be the cleanest solution.

    •  

    4. Import Users and Assign Roles Post-Import (More Steps):

    • Import Users Without Role Mapping: Attempt to import the users using Scribe, accepting that it might initially fail due to the foreign key constraint.

    • Identify Failed User Records: Determine the SystemUserId values of the users that failed to import.

    • Use Power Automate or Bulk Edit in the UI: After the failed import, you could potentially:

      • Power Automate: Create a flow that triggers on the creation of a user without a role (this might be tricky if the creation fails at the constraint level).

      • Bulk Edit in UI (Less Scalable): If the number of failed users isn't too large, you could try to manually assign the "Stub User" role to these users in the Power Platform Admin Center or Dynamics 365 UI after the import. However, for 500,000 records, this is impractical.


      •  

    Identifying What Your Colleague Did (If You Can't Get an Answer):

    If your colleague remains unavailable, you could try to investigate the following in the environments where the import worked:

    • Audit Logs: Check the audit logs around the time the imports were successful for any configuration changes related to security roles or user creation.

    • Solutions: Examine any recently deployed unmanaged solutions for custom workflows, plugins, or configuration entities that might be involved in user creation or role assignment.

    • Database Changes (Use with Extreme Caution and Knowledge): If you have database access and a strong understanding of the schema, you could compare the database schema and constraints related to SystemUserBase and SystemUserRoles between a working and a non-working environment. However, directly modifying the database is highly discouraged and unsupported.

    •  

    Recommendation:

    The most robust and supportable solution is to map a default "Stub User" security role in your Scribe ETL process. This ensures that every imported user, even inactive ones, has the required association with a security role, satisfying the foreign key constraint. Creating a specific "Stub User" role provides better control and clarity for these legacy records.

    Focus on modifying your Scribe script to include the logic for looking up the RoleId of your chosen default role and inserting the necessary records into the SystemUserRoles table during the user import.

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 41 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 39

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans