Syncing Jira Date fields to an Azure Date/Time field

Originally asked by Howard Kenny on 20 November 2020 (original question)


Hey,

Is it possible to map a Jira date field to a date/time field in Azure DevOps? Naturally, expecting the time aspect to default to 00.00.

Cheers.


Answer by Howard Kenny on 22 November 2020

For any potential future readers, this was the solution Francis gave me:

import java.text.SimpleDateFormat 
...

def sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
def targetDate 
if (replica.customFields."Planned Start Date"?.value){
    targetDate = sdf.format(replica.customFields."Planned Start Date".value)
    workItem."Microsoft.VSTS.Scheduling.StartDate" = targetDate
}
if (replica.customFields."Planned End Date"?.value){
    targetDate = sdf.format(replica.customFields."Planned End Date".value)
    workItem."Microsoft.VSTS.Scheduling.TargetDate" = targetDate
}

Answer by Francis Martens (Exalate) on 20 November 2020

Yes - it should - but the devil is in the eating of the pudding.

What fields do you need to sync?


Comments:

Howard Kenny commented on 21 November 2020

Ha!

Iā€™m sending this in the Outgoing Sync:

replica.customFields."Planned End Date" = issue.customFields."Planned End Date"
replica.customFields."Planned Start Date" = issue.customFields."Planned Start Date"

ā€¦and this is the Incoming Sync section:

    workItem.customKeys."Microsoft.VSTS.Scheduling.StartDate" = replica.customFields."Planned Start Date".value
    workItem.customKeys."Microsoft.VSTS.Scheduling.TargetDate" = replica.customFields."Planned End Date".value

ā€¦but nothing populates the fields Start Date and Target Date in DevOps.

For info, ā€œMicrosoft.VSTS.Scheduling.StartDateā€ was taken from the JSON.

Iā€™m also struggling to sync time tracking fields. This doesnā€™t seem to work:

workItem.customKeys."Microsoft.VSTS.Scheduling.Effort"   = replica.originalEstimate
Francis Martens (Exalate) commented on 21 November 2020

I had to do some experimentation myself ā€¦

Found the trick - you have to use a string representation of the date

Incoming, Tested

import java.text.SimpleDateFormat 
...
def sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
def targetDate = sdf.format(new Date())

//throw new Exception("Target date = ${targetDate}")
workItem."Microsoft.VSTS.Scheduling.StartDate" = targetDate

Also added some more documentation on how to access the fields

How to sync work item fields obtained through a REST API call

Howard Kenny commented on 22 November 2020

Iā€™m having issues with thatā€¦

'Script cannot be saved. Details: startup failed: Script297.groovy: 59: Unknown type: IMPORT at line

Iā€™m thinking you didnā€™t expect me to copy and paste that whole snippet into my incoming script and instead do something special with ā€˜import java.text.SimpleDateFormatā€™?

Francis Martens (Exalate) commented on 22 November 2020

Euh - how does the script look like when trying to save?

Howard Kenny commented on 22 November 2020

I tried a few ways, not fully understanding how I was supposed to insert it (and not being convinced by any of my attempts!), butā€¦

import java.text.SimpleDateFormat 
        ...
        def sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")
        def targetDate = sdf.format(new Date())
        
        //throw new Exception("Target date = ${targetDate}")
        workItem."Microsoft.VSTS.Scheduling.StartDate" = targetDate
        
        workItem.customKeys."Microsoft.VSTS.Scheduling.StartDate" = replica.customFields."Planned Start Date".value
        workItem.customKeys."Microsoft.VSTS.Scheduling.TargetDate" = replica.customFields."Planned End Date".value

I kept my two original lines at the end as I couldnā€™t see how your snippet referenced the source Jira Planned Start Date fields.

Francis Martens (Exalate) commented on 22 November 2020

Ah - remove the elipsis (ā€¦)
This is to denote any other code, but it is not a valid groovy construct

Also - remove the entries with the ā€˜customKeysā€™ - it makes no sense
Of course - you will have to stringify the ā€˜Planned Start Dateā€™ to assign it to the Start Date.

Roderick Stevens commented on 05 June 2023

I get an error when I use the

import java.text.SimpleDateFormat?

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.