TFS4JIRA Self-Hosted | Error: Work item XXX does not exist, or you do not have permission to read it.

Direction: Jira → TFS / ADO only!

When the initial synchronization mode 3 or 4 is started (JIRA->ADO/TFS), but there is no visible progress and in addition, it seems like the sync is stuck in an endless loop and in the LOG section, the following error is visible:

2022-10-20 06:56:20,789 [34] DEBUG Initial.InitialSynchronizationJiraToTfsService - Initial synchronization: Jira issue STA40-477 is already paired with TFS work item #617 and synchronization mode is ResyncCreate -- trying to unlink existing TFS work item and create a new TFS work item
2022-10-20 06:56:20,914 [34] ERROR Workers.SynchronizationWorker - Error running initial synchronization for #78b50692-0556-4c9d-be37-3deb06495665
Microsoft.VisualStudio.Services.Common.VssServiceException: TF401232: Work item 617 does not exist, or you do not have permissions to read it.

Most likely counterpart item in Jira has been deleted.

A counterpart is an item created in the designated environment (in this case, in JIRA) from the source item (in this case, ADO/TFS).

TFS4JIRA, during sync or migration, stores data in at least 3 locations: database, which also holds profile configuration, Jira and ADO/TFS custom field, Jira issue properties to prevent comments and attachments duplicates.

What to do if counterpart(s) have been deleted?

  1. If the problem is related to only a few Jira issues, the best way is to create ‘fake’ ADO/TFS items and place the corresponding TFS ID in a custom filed in Jira and Jira ID on TFS side. Now when running INITIAL SYNC (mode 4), TFS4JIRA will be able to find the counterpart, will delete it and create new pair.

  2. If the problem is related to the whole project or a large number of Jira issues, please follow the below stream of tasks.

    1. Create a new CUSTOM field in Jira environment that will hold ADO/TFS ID (even thou one is already created). Do not forget to add that custom field to relevant screens.

    2. Setup this newly created custom field in TFS4JIRA project where the problem exists.

    3. Ideally, erase all created work items on ADO/TFS side in the designed project.

    4. Run initial synchronization mode 1. This synchronization will create new work items, unfortunately, without all the comments and attachments.

    5. Now once the above initial sync is finished, once again start Initial Sync, this time mode 4.

    6. When finished, all new counterparts are present in ADO / TFS, with all the comments and attachments migrated/synced.

  3. If the problem is related to the whole project.

    1. Attached Phyton script removed any TFS4JIRA related information from Issue Properties

    2. Script runs DELETE request on ALL issues in PROJECT

This method 2 and 3 should not be used in a live production environment.