Sync affectsversion from Servicenow to Jira

Originally asked by Rajeswari T on 06 October 2022 (original question)


Servicenow outgoing :

replica.u_product_version = entity.u_product_version

Jira Incoming :

issue.affectedVersions = replica
.u_product_version
.``collect { v -> nodeHelper.getVersion([v.name](http://v.name), project) }
.``findAll``{it !=``null``}

note : wherein product version is a select list field type.


Comments:

Serhiy Onyshchenko commented on 06 October 2022

Hey, Rajeswari T

What does an error print if you add this in front of your snippet and sync an issue towards it?

debug.error("u_product_version=${replica.u_product_version} type=${replica.u_product_version.class}")

Regards, Serhiy

Rajeswari T commented on 06 October 2022

No such property: name for class: java.lang.string

Serhiy Onyshchenko commented on 07 October 2022

Hey, Rajeswari T , please comment out your other snippet:

//issue.affectedVersions = replica
//  .u_product_version
//  .collect { v -> nodeHelper.getVersion(v.name, project) }
//  .findAll{it != null}

Regards, Serhiy

Rajeswari T commented on 07 October 2022

u_product_version=9.0.0.0type=class: java.lang.string

Rajeswari T commented on 10 October 2022

Any update?

Serhiy Onyshchenko commented on 11 October 2022

So now you know the type and the value of the `replica.u_product_version` field, thus, you may

remove the debug.error line and replace the commented

//issue.affectedVersions = replica
//  .u_product_version
//  .collect { v -> nodeHelper.getVersion(v.name, project) }
//  .findAll{it != null}

do:

issue.affectedVersions += nodeHelper.getVersion(
  replica.u_product_version, 
  project
)

Let me know, how it goes, Regards, Serhiy.

Rajeswari T commented on 11 October 2022

Serhiy Onyshchenko Same error again :

No Such Property: Project for class: Script 299

Rajeswari T commented on 14 October 2022

Serhiy Onyshchenko - i tried to replicate the same product verison to another version picker custom field called “Identified in Release”. But it doesn’t seem to be working

Servicenow outgoing :

replica.u_product_version = entity.u_product_version

Jira incoming :

issue.customFields."Identified in Release".value = nodeHelper.getVersion(
  replica.u_product_version, 
  issue.project ?: nodeHelper.getProject(issue.projectKey)
)
Serhiy Onyshchenko commented on 14 October 2022

Hey, Rajeswari T
Isn’t Version picker custom field a multi-value custom field?
In that case I’d suggest to do

issue.customFields."Identified in Release".value = (issue.customFields."Identified in Release".value ?: []) 
issue.customFields."Identified in Release".value += nodeHelper.getVersion(
  replica.u_product_version, 
  issue.project ?: nodeHelper.getProject(issue.projectKey)
)

Or, considering

short-hand-syntax-for-custom-fields

issue."Identified in Release" // same as `issue.customFields."Identified in Release".value`
issue."Identified in Release" = (issue."Identified in Release" ?: []) 
issue."Identified in Release" += nodeHelper.getVersion(
  replica.u_product_version, 
  issue.project ?: nodeHelper.getProject(issue.projectKey)
)

Regards, Serhiy.

Answer by Serhiy Onyshchenko on 11 October 2022

Please, try

issue.affectedVersions += nodeHelper.getVersion(
  replica.u_product_version, 
  issue.project ?: nodeHelper.getProject(issue.projectKey)
)

Comments:

Rajeswari T commented on 11 October 2022

It works. Thanks a lot