Unable to sync (via script connection) custom field in Jira to custom field in DevOps

Originally asked by Rosie Dias on 28 May 2021 (original question)


I have a two-way sync enabled via the “Script” between Jira Server & Azure DevOps, and I am unable to sync a custom field from Jira to a custom field in DevOps.

On Jira side I have put in Outgoing Sync:

replica.customFields.“Jira PBI Reference” = issue.customFields.“MainPBINum”

On DevOps side I have put in Incoming Sync:

workItem.customFields.“Jira PBI Reference” = replica.customFields.“MainPBINum”

Also the Jira Assignee & Status Fields are not being passed to DevOps (using standard script with no modifications for these fields on both Incoming & Outgoing sides) all other fields are OK:

replica.assignee = workItem.assignee

replica.assignee = issue.assignee

It is probably something simple I am missing?

Thanks in advance for your help,

Rosie


Answer by Ariel Aguilar on 28 May 2021

Hi Rosie,

To sync the custom fields you can do:

Jira Outgoing Script:

replica.customFields."Jira PBI Reference" = workItem.customKeys."MainPBINum"

Azure Incoming:

workItem.customKeys."MainPBINum"?.value = replica.customFields."Jira PBI Reference"?.value

For assignee you can use the following method:

issue.assignee = nodeHelper.getUser(replica.assignee.key)

This helps to set the local issue assignee based on the remote issue assignee using the method.

For the method to work on Azure DevOps, make sure that the user is part of the team that has access to the Azure DevOps project.

To sync statuses on Azure DevOps you can check this out:

https://docs.idalko.com/exalate/x/kgF1Aw

Let me know if this works for you,

Kind regards,

Ariel


Answer by Rosie Dias on 31 May 2021

I believe this error will result when Assignee hasn’t yet been picked. Is there a way around this?


Comments:

Ariel Aguilar commented on 02 June 2021

Hi Rosie,

Could you please give it a try and change it to:

issue.assignee = nodeHelper.getUserByEmail(replica.assignee?.email)

Kind regards,

Ariel

Answer by Rosie Dias on 31 May 2021

Hi Ariel,

I changed the above custom field in Jira Outgoing script to teh below and it seems to work :smile::

**Jira Outgoing Sync:**replica.customFields.“Jira PBI Reference” = issue.customKeys.“MainPBINum”

However the Assignee does not work :sad: as you wrote above, I get the following error message:

Assignee line: issue.assignee = nodeHelper.getUser(replica.assignee.key)

Error message: Cannot get property ‘key’ on null object


Comments:

Daniel Carvajal commented on 27 October 2021

Hi Rosie Dias

Can you change that line to:

issue.assignee = nodeHelper.getUser(replica.assignee?.key)

The ?. works to avoid throwing errors when receiving null values.

Hope this is helpful.