From 868d297518aabedce50e60c18b02dc46266f1d97 Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Sat, 22 Jul 2023 18:20:33 +0200 Subject: [PATCH] Fix for removed or replaced WIFields --- .../WorkItemImport/WitClient/JsonPatchDocUtils.cs | 5 ----- .../WorkItemImport/WitClient/WitClientUtils.cs | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/WorkItemMigrator/WorkItemImport/WitClient/JsonPatchDocUtils.cs b/src/WorkItemMigrator/WorkItemImport/WitClient/JsonPatchDocUtils.cs index 68c87686..e3e6a727 100644 --- a/src/WorkItemMigrator/WorkItemImport/WitClient/JsonPatchDocUtils.cs +++ b/src/WorkItemMigrator/WorkItemImport/WitClient/JsonPatchDocUtils.cs @@ -13,11 +13,6 @@ public static JsonPatchOperation CreateJsonFieldPatchOp(Operation op, string key throw new ArgumentException(nameof(key)); } - if (value == null) - { - throw new ArgumentException(nameof(value)); - } - return new JsonPatchOperation() { Operation = op, diff --git a/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs b/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs index 1b538f8b..7aee94c9 100644 --- a/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs +++ b/src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs @@ -526,9 +526,18 @@ public void SaveWorkItemFields(WorkItem wi) object val = wi.Fields[key]; - patchDocument.Add( - JsonPatchDocUtils.CreateJsonFieldPatchOp(Operation.Add, key, val) - ); + if (val == null || val.ToString() == "") + { + patchDocument.Add( + JsonPatchDocUtils.CreateJsonFieldPatchOp(Operation.Remove, key, null) + ); + } + else + { + patchDocument.Add( + JsonPatchDocUtils.CreateJsonFieldPatchOp(Operation.Replace, key, val) + ); + } } try