Tasks and Calendar Entries: Removing Duplicate User Assignments
Sometimes the same user is included in a calendar event, or assigned to a task, multiple times. This can be a result of User Mapping or data error in the legacy system.
Below is an example of how this can happen.
A calendar event includes user John Smith and Henry Jones. Henry Jones is an inactive user in the legacy system who will not have a user account in the destination system. The firm has decided to map Henry's user data to John Smith, an active user in the destination system. As a result, the calendar entry includes John Smith twice. Once because he was originally included in the meeting, and once because Henry Jone's user data was mapped to him.
A similar situation can happen with tasks being assigned to the same user multiple times.
The script below will remove these duplicate user assignments.
- GO
- WITH P AS
- (
- SELECT
- cpu.Id,
- ROW_NUMBER() OVER (PARTITION BY cpu.Final_CalendarEntry_Id, u.Result_Id ORDER BY (SELECT NULL)) rowNum
- FROM
- __M_CalendarEntries_Participating_Users cpu
- INNER JOIN
- __M_Users u
- ON u.Id = cpu.Final_User_Id
- ),
- P2 AS
- (
- SELECT
- Id
- FROM
- P
- WHERE 1=1
- AND rowNum > 1
- )
- UPDATE
- __M_CalendarEntries_Participating_Users
- SET
- Final_Status= 'Deleted',
- Comment = 'Duplicate assignment removed'
- WHERE 1=1
- AND Id IN
- (
- SELECT Id FROM P2
- );
- GO
- WITH P AS
- (
- SELECT
- tau.Id,
- ROW_NUMBER() OVER (PARTITION BY tau.Final_TaskEntry_Id, u.Result_Id ORDER BY (SELECT NULL)) rowNum
- FROM
- __M_Tasks_AssignedTo_Users tau
- INNER JOIN
- __M_Users u
- ON u.Id = tau.Final_User_Id
- ),
- P2 AS
- (
- SELECT
- P.Id
- FROM
- P
- WHERE 1=1
- AND rowNum > 1
- )
- UPDATE
- __M_Tasks_AssignedTo_Users
- SET
- Final_Status = 'Deleted',
- Comment = 'Duplicate assignment removed'
- WHERE 1=1
- AND Id IN
- (
- SELECT
- Id
- FROM
- P2
- );
Related Articles
Moving Documents into Matters that are Nested under Calendar Entries
--The following script moves documents that are nested under Calendar Entries to be nested under Matters instead. UPDATE __M_Documents_Digital_Files SET Final_Folder_RelativePath = '\Calendar Attachments\', Final_Parent_Type = ...
Tasks: Append Assigned To and Completed By to Descriptions
The script below will append the text 'Assigned to User: {firstName lastName}' and 'Completed by User: {firstName lastName}' to the end of the task description in cases where the users Email address was changed on the __M_Users table as a result of ...
Copy Calendar Entry Dates into Custom Field Values
Some systems let you create custom fields that reference a Calendar Entry. When moving custom fields into a system that does not support this, an easy workaround would be to turn these custom fields into DateTime custom fields by copying in the start ...
Moving Documents into Matters that are Nested under Tasks
--The following script moves documents that are nested under Tasks to be nested under Matters instead. UPDATE __M_Documents_Digital_Files SET Final_Folder_RelativePath = '\Task Attachments\', Final_Parent_Type = Relationships.Final_RelatedTo_Type, ...
Convert User-Select/Contact-Select Custom Fields => Participants
Some systems do not support User-Select or Contact Select custom fields. The following query will transform User-Select fields into Matter Participants. This script can easily be adapted for Contact-Select fields. -- Transform Custom Fields on ...