Clone wiki

UseTFS / Groovy expressions

With version 2.5.3 you have possibility to use Groovy language in Work Synchronizers.

It's available on two levels

  • top level (with acess to entire collection of mapped Issue/Work item values)
  • field level (with access only to particular field value)

Top level

You can access the following variables:

  • currentDirection - allows you to distinguish in which way the transformation is currently applied. Either "TFS2JIRA" or "JIRA2TFS"
  • map - dictionary with all mapped field values after transformations. Any modification of field value in map will affect the synchronization.
  • jiraFieldValues - contains source values when currentDirection == "JIRA2TFS"
  • tfsFieldValues - contains source values when currentDirection == "TFS2JIRA" Since version 2.8.1:
  • tfsParentId - contains ID of work item that is parent to current one, otherwise null or empty
  • jiraParentId - contains key of issue is parent to current one, otherwise null or empty. Due to performance considerations the two variables above are set only for new items (will be null if current issue/work item has been already synchronized and has corresponding one in the other system).

Example:

if(currentDirection=="JIRA2TFS")
{
  String targetTeamProject = map.get("System.TeamProject");
  if(targetTeamProject == "Test")
  {
    map.put("System.AssignedTo","User");
    if(map.containsKey("System.Reason"))
    {
      map.removeKey("System.Reason");
    }
  }
}
else
{
  // Let's say we want to combine description field out of two fields
  String tfsDescription = tfsFieldValues.get("System.Description");
  String tfsReproSteps = tfsFieldValues.get("Microsoft.VSTS.TCM.ReproSteps");
  map.put("Description",tfsDescription + "\n" + tfsReproSteps);
}

Example 2 - Setting jira task or subtask type based on having parent in tfs:

if(currentDirection=="TFS2JIRA")
{
  if(tfsParentId == null || tfsParentId == "")
  {
      map.put("Type","Task");
  }
  else
  {
      map.put("Type","Sub-task");
  }
}

Field level

You can access the following variables:

  • currentDirection - allows you to distinguish in which way the transformation is currently applied. Either "TFS2JIRA" or "JIRA2TFS"
  • inputValue - the original field value
  • returnValue - value after all the transformations. Set this variable to override result.

Example:

if(currentDirection=="JIRA2TFS")
{
  returnValue = inputValue+"_suffix";
}
else
{
  if(inputValue=="admin")
  {
    returnValue = "Need attention here!";
  }
  else
  {
    returnValue = "Just a regular stuff";
  }
}

Example 2 - recalculating time estimate field:

if(currentDirection=="JIRA2TFS")
{
  String timeString = inputValue;
  Integer timeVal = Integer.parseInt(timeString);
  if(timeVal > 0) {
    timeVal = timeVal / 3600;
  }
  returnValue = timeVal.toString();
}

Updated