Jira:如何获取自定义 IssueEventListener 中自定义字段的先前值

发布于 2024-09-15 21:30:38 字数 455 浏览 19 评论 0原文

那么如何获取自定义字段前一个 在 Jira IssueEventListener 中?我正在为 issuesUpdated(IssueEvent) 事件编写一个自定义处理程序,如果某个自定义字段发生更改,我想更改处理程序的行为。为了检测变化的类型,我想比较之前的值和当前的值。

(我不是在问如何获取其当前值 - 我知道如何从相关问题中获取该值)

我正在 Windows 上针对 Jira 4.0.2 进行开发。

扫描更改历史记录以获取最后一个已知值的最佳方法是吗?

List changes = changeHistoryManager.getChangeHistoriesForUser(issue, user);

So how does one obtain the previous value of a custom field in a Jira IssueEventListener? I am writing a custom handler for the issueUpdated(IssueEvent) event and I would like to alter the handler's behavior if a certain custom field has changed. To detect the type of change I would like to compare the previous and current values.

(I'm am not asking about how to obtain its current value - I know how to get that from the related Issue)

I am developing against Jira 4.0.2 on Windows.

Is the best way to scan the change history for the last known value?

List changes = changeHistoryManager.getChangeHistoriesForUser(issue, user);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不…忘初心 2024-09-22 21:30:38

我假设原始发布者正在使用 Java 编写 JIRA 插件。我无法确定如何在 JIRA v4.0.2 中完成此任务,但以下是我如何使用 JIRA v5.0.2 完成此任务(解决方案很可能是相同的):

public void workflowEvent( IssueEvent event )
{
  Long eventTypeId = event.getEventTypeId();
  if( eventTypeId.equals( EventType.ISSUE_UPDATED_ID ) )
  {
    List<GenericValue> changeItemList = null;
    try
    {
      changeItemList = event.getChangeLog().getRelated( "ChildChangeItem" );
    }
    catch( GenericEntityException e )
    {
      // Error or do what you need to do here.
      e.printStackTrace();
    }

    if( changeItemList == null )
    {
      // Same deal here.
      return;
    }

    Iterator<GenericValue> changeItemListIterator = changeItemList.iterator();
    while( changeItemListIterator.hasNext() )
    {
      GenericValue changeItem = ( GenericValue )changeItemListIterator.next();
      String fieldName = changeItem.get( "field" ).toString();
      if( fieldName.equals( customFieldName ) ) // Name of custom field.
      {
        Object oldValue = changeItem.get( "oldvalue" );
        Object newValue = changeItem.get( "newvalue" );
      }
    }
  }
}

changeItem 的一些可能的关键值是:

  • newvalue
  • oldstring
  • 字段
  • id
  • fieldtype
  • newstring
  • oldvalue

对于许多自定义字段类型,Object oldValue 可能只是一个字符串。但我认为并非所有情况都如此。

I'm assuming the original poster is writing a JIRA plugin with Java. I cannot be certain of how to accomplish this task in JIRA v4.0.2, but here is how I managed to do so with JIRA v5.0.2 (the solutions may very well be the same):

public void workflowEvent( IssueEvent event )
{
  Long eventTypeId = event.getEventTypeId();
  if( eventTypeId.equals( EventType.ISSUE_UPDATED_ID ) )
  {
    List<GenericValue> changeItemList = null;
    try
    {
      changeItemList = event.getChangeLog().getRelated( "ChildChangeItem" );
    }
    catch( GenericEntityException e )
    {
      // Error or do what you need to do here.
      e.printStackTrace();
    }

    if( changeItemList == null )
    {
      // Same deal here.
      return;
    }

    Iterator<GenericValue> changeItemListIterator = changeItemList.iterator();
    while( changeItemListIterator.hasNext() )
    {
      GenericValue changeItem = ( GenericValue )changeItemListIterator.next();
      String fieldName = changeItem.get( "field" ).toString();
      if( fieldName.equals( customFieldName ) ) // Name of custom field.
      {
        Object oldValue = changeItem.get( "oldvalue" );
        Object newValue = changeItem.get( "newvalue" );
      }
    }
  }
}

Some possible key values for changeItem are:

  • newvalue
  • oldstring
  • field
  • id
  • fieldtype
  • newstring
  • oldvalue
  • group

For many of the custom field types Object oldValue is probably just a String. But I don't think that's true for every case.

凹づ凸ル 2024-09-22 21:30:38

试试这个例子:

String codeProjetOldValue= "";

List<GenericValue> changeItemList = issueEvent.getChangeLog().getRelated("ChildChangeItem");                
for (GenericValue genericValue : changeItemList) {                          
    if(champCodeProjet.equals(genericValue.get("field"))){
        codeProjetOldValue=genericValue.getString("oldstring");
        break;
    }
}

注意:champCodeProjet 是自定义字段的名称。

Try this example :

String codeProjetOldValue= "";

List<GenericValue> changeItemList = issueEvent.getChangeLog().getRelated("ChildChangeItem");                
for (GenericValue genericValue : changeItemList) {                          
    if(champCodeProjet.equals(genericValue.get("field"))){
        codeProjetOldValue=genericValue.getString("oldstring");
        break;
    }
}

Note that : champCodeProjet is the name of customfield.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文