【问题标题】:Is there any way to merge fields without adding the doneMatch into the field?有没有办法在不将 doneMatch 添加到字段中的情况下合并字段?
【发布时间】:2020-08-03 23:43:36
【问题描述】:

我们需要将两个字段合并为一个。在配置中,有一个“doneMatch”特殊字符串,这似乎被附加到合并字段中。为什么需要这个,有没有办法不将它也附加到目标字段?

例如,我有:
src.fieldA = "城市"
src.fieldB = "状态"

我想将这 2 个字段合并到 target.fieldA 作为“城市:州”。但是,我最终得到的是“City:State##DONE##”,我可以更改配置文件,以便它使用不同的 doneMatch,但它不能为空或为空.. 所以如果我将其更改为“; ",那么结果字段将是 "City: State;"。由于某种原因,我必须结束字符/字符串。这是做什么用的?如果我将字段与较新的更新同步,它是否会检测到 target.fieldA 中以前的##DONE## 并认为它已经完成了合并,所以不会进行任何新的更改?

谁能发给我有关此功能的更多信息?

【问题讨论】:

  • 抱歉,我应该在一周或更短的时间内收到反馈。
  • 没关系。我会等待你的反馈。随时让我知道进展情况。如果你还有问题,我也可以给你一些帮助。
  • 不幸的是,它实际上将“&nbsp”作为字符串,并将其附加到字段中。
  • 嗨@Sclieu Yu。我再次测试它,答案只能在Text (multiple lines) 字段上工作。请检查更新。您可以创建一个新字段并将其设置为目标字段。
  • 好的,我刚刚检查了它,doneMatch 是测试已经发生的合并的糟糕方法......我正在研究它。

标签: azure-devops-extensions azure-devops-migration-tools


【解决方案1】:

我已经更新了 v9.0.1 的代码,它改变了 FieldMerge 的工作方式。它不再使用 doneMatch,而是要求所有 3 个字段都不同,如果已经完成则跳过。

 if (source.Fields.Contains(config.sourceField1) && source.Fields.Contains(config.sourceField2))
            {
                var val1 = source.Fields[config.sourceField1].Value != null ? source.Fields[config.sourceField1].Value.ToString() : string.Empty;
                var val2 = source.Fields[config.sourceField2].Value != null ? source.Fields[config.sourceField2].Value.ToString() : string.Empty;
                var valT = target.Fields[config.targetField].Value != null ? target.Fields[config.targetField].Value.ToString() : string.Empty;
                var newValT = string.Format(config.formatExpression, val1, val2);

                if (valT.Equals(newValT))
                {
                    Trace.WriteLine(string.Format("  [SKIP] field already merged {0}:{1}+{2} to {3}:{4}", source.Id, config.sourceField1, config.sourceField2, target.Id, config.targetField));
                } else
                {
                    target.Fields[config.targetField].Value = string.Format(config.formatExpression, val1, val2) + config.doneMatch;
                    Trace.WriteLine(string.Format("  [UPDATE] field merged {0}:{1}+{2} to {3}:{4}", source.Id, config.sourceField1, config.sourceField2, target.Id, config.targetField));
                }

            }

https://github.com/nkdAgility/azure-devops-migration-tools/pull/529

【讨论】:

    【解决方案2】:

    使用 Azure Devops 迁移工具测试字段合并,我也可以重现这种情况。 configuration.json 文件中需要doneMatch 字段(默认为##Done##)。

    似乎没有办法避免在目标字段中添加donematch。由于我不是这个工具的开发者,所以不清楚这个字段的作用。

    我想分享一个解决此问题的解决方法。

    解决方法:

    您可以尝试将" " 设置为doneMatch 字段。 ("doneMatch": " ")

    例如:

     "FieldMaps": [
        {
          "ObjectType": "VstsSyncMigrator.Engine.Configuration.FieldMap.FieldMergeMapConfig",
          "WorkItemTypeName": "*",
          "sourceField1": "System.Description",
          "sourceField2": "Microsoft.VSTS.Common.AcceptanceCriteria",
          "targetField": "System.Description",
          "formatExpression": "{0} {1}",
          "doneMatch": " "
        }
    

    由于配置文件是Json文件,所以可以使用" "来表示空格。

    结果:

    是否会检测到 target.fieldA 中的前一个 ##DONE## 和 认为它已经完成了合并,所以不会进行任何新的更改

    根据我的测试,目标字段中的##Done##不会影响其他操作。您仍然可以对该字段进行操作。

    更新:

    上述方法只适用于字段类型:Text (multiple lines)。如果字段为其他类型,则此方法无效。

    您可以创建一个新字段 (Text (multiple lines))。然后你可以将目标字段设置为新字段。

    例如

     "FieldMaps": [
    
     
        {
          "ObjectType": "VstsSyncMigrator.Engine.Configuration.FieldMap.FieldMergeMapConfig",
          "WorkItemTypeName": "*",
          "sourceField1": "Custom.test1",
          "sourceField2": "Custom.test2",
          "targetField": "Custom.test3",
          "formatExpression": "{0} {1}",
          "doneMatch": " "
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多