Questions for Confluence license has expired.

Please purchase a new license to continue using Questions for Confluence.

Synchronizing System field with a cascade select value

 
2
1
0

Hi,

I'm trying to synchronize a system field "Affects Version/s" (affectedVersions) to a value from a cascade field.
I've tried the following but it does not seem to work. Could you please help me on this?

if (replica.customFields."Product"?.value?.child?.value != null) { issue.affectedVersions = replica.customFields."Product"?.value?.child?.value }


Here, "Product" is a cascade select with a parent and child values.


BR,
Sujan

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Francis,


      I've been getting the following error after I tries your suggestion and I'm not able to find the reason for it as well.Could you please help.

      Error Detail Message:

      Script error details: No such property: firstSync for class: Script6014. Error line: Script6014.groovy:86

      Error Stack Trace:

      com.exalate.api.exception.script.CreateProcessorException: Script error details: No such property: firstSync for class: Script6014. Error line: Script6014.groovy:86 at com.exalate.error.services.ScriptExceptionCategoryService$.wrapAsCreateProcessorException(ScriptExceptionCategoryService.scala:53) at com.exalate.processor.jira.JiraCreateIssueProcessor.createIssue(JiraCreateIssueProcessor.java:147) at com.exalate.replication.request.CreateIssueSyncRequestState.transition(CreateIssueSyncRequestState.java:73) at com.exalate.replication.request.CreateIssueSyncRequestState.transition(CreateIssueSyncRequestState.java:24) at com.exalate.replication.in.RequestProcessorService.processSyncRequest(RequestProcessorService.java:324) at com.exalate.replication.in.RequestProcessorService.processSyncRequestsForIssue(RequestProcessorService.java:181) at com.exalate.replication.in.RequestProcessorService.processSyncRequests(RequestProcessorService.java:128) at com.exalate.replication.in.RequestWorker$1.run(RequestWorker.java:81) at com.exalate.util.ClusteredSensitiveExecutorService.executeHandlingLocks(ClusteredSensitiveExecutorService.java:32) at com.exalate.replication.in.RequestWorker.run(RequestWorker.java:74) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: com.exalate.api.exception.script.ScriptException: No such property: firstSync for class: Script6014. Error line: Script6014.groovy:86 at com.exalate.error.services.ScriptExceptionCategoryService.categorizeProcessorAndIssueTrackerExceptionsIntoScriptExceptions(ScriptExceptionCategoryService.scala:35) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:43) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:34) at com.exalate.processor.jira.JiraCreateIssueProcessor.executeCreateProcessor(JiraCreateIssueProcessor.java:215) at com.exalate.processor.jira.JiraCreateIssueProcessor.createIssue(JiraCreateIssueProcessor.java:131) ... 15 more Caused by: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: firstSync for class: Script6014 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:151) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264) at com.exalate.processor.ExalateProcessor.execute(ExalateProcessor.java:71) at com.exalate.processor.ExalateProcessor.executeProcessor(ExalateProcessor.java:41) ... 18 more Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: firstSync for class: Script6014 at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:348) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:145) ... 21 more Caused by: groovy.lang.MissingPropertyException: No such property: firstSync for class: Script6014 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:51) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231) at Script6014.run(Script6014.groovy:86) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:345) ... 22 more


      BR,

      Sujan

      1. user-3fd1a

        On what version of Exalate are you.  If it is pre 4.6, you will  get this error

      2. Sujan Karanjeet

        Thanks, I updated it to 4.6 to get the sync. working. However, I didn't get anything in the "Affects Version".

      3. user-3fd1a

        It is always helpful to  see what the end result is of all that hard work


        import com.exalate.api.exception.IssueTrackerException
        
        def foundVersion = nodeHelper.getVersion(targetVersionName,targetProject)
        throw new IssueTrackerException("Found version for '${targetVersionName}' in project '${targetProject}' is  '${foundVersion}' }
        
        



        The exception will throw an error providing the message.

        Massaging the script will get what you want.



        Please give it a try and  let me know

      4. Sujan Karanjeet

        Hi Francis,


        I'm not getting value for the parent cascade field. I get "com.exalate.basic.domain.hubobject.v1.BasicHubProject@5866c90" in the cascade field's parent value.


        Script error details: javax.script.ScriptException: com.exalate.api.exception.IssueTrackerException: Found version for '6.9.1' in project 'com.exalate.basic.domain.hubobject.v1.BasicHubProject@5866c90' is 'null'. Error line: Script607.groovy:98


        BR,

        Sujan

      5. user-3fd1a

        Can you check if the versionName is existing in the project?  With the following statement you can extract the key



        import com.exalate.api.exception.IssueTrackerException
        
        def foundVersion = nodeHelper.getVersion(targetVersionName,targetProject)
        throw new IssueTrackerException("Found version for '${targetVersionName}' in project '${targetProject}' (${targetProject.key}) is  '${foundVersion}' }
      6. Sujan Karanjeet

        Hi Francis,


        I have the following lines included in my create processor. Not sure what I'm doing wrong. Could you please help? I don't get any project or the project key.


        // default to '1.0' if the product child has no value
        def targetVersionName = replica.customFields."Product"?.value?.child?.value ?: "1.0"

        // getVersion needs a project object. During the firstSync this is not set yet
        def targetProject = firstSync ? nodeHelper.getProject("DEMO") : issue.project


        issue.affectedVersions += nodeHelper.getVersion(targetVersionName,targetProject)


        import com.exalate.api.exception.IssueTrackerException


        def foundVersion = nodeHelper.getVersion(targetVersionName,targetProject)
        throw new IssueTrackerException("Found version for '${targetVersionName}' in project '${targetProject}' (${targetProject.key}) is '${foundVersion}'")


        BR,

        Sujan

      7. user-3fd1a

        What is the throw throwing

        Does the project 'DEMO' exists


      8. Sujan Karanjeet

        Hi,


        I'm using the project "Test", with key "TEST" and here's the exception:


         Found version for '6.9.1' in project 'com.exalate.basic.domain.hubobject.v1.BasicHubProject@5866c90' (TEST) is 'null'. Error line: Script1066.groovy:91


        BR,

        Sujan

      9. user-3fd1a

        Try 

        def versionList = issue.project.versions.collect { "'${it.name}'" }.join(", ")
        throw new IssueTrackerException("Versions = ${versionList}")
        
        Can  you check if  the version you  are looking  for is in the list?
      10. Sujan Karanjeet

        I get the versions fine: Versions = '5.7.0', '5.8.1_HW', '5.7.1', '5.7.2', '5.9.0', '5.1.1 dev', '5.9....."

        And I get the targetVersionName with: 

        def targetVersionName = replica.customFields."Product"?.value?.child?.value ?: "1.0"


        However, I cannot get the project.

        def targetProject = firstSync ? nodeHelper.getProject("TEST") : issue.project

        This is the command that's failing.



      11. user-3fd1a

        Given all this information


        • TargetProjectKey = TEST
        • TargetVersionName =  6.9.1
        • VersionList is '5.7.0', '5.8.1_HW', '5.7.1', '5.7.2', '5.9.0', '5.1.1 dev', '5.9.....
        • nodeHelper.getVersion is returning null 
        • Can you confirm that the version is in the versionlist and the method is not found?



      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Sujan Karanjeet


      You need to allocate a version object to affectedVersions.  So you need to find the correct version using the GetVersion method


      Something like


      // default to '1.0' if the product child has no value
      def targetVersionName = replica.customFields."Product"?.value?.child?.value ?: "1.0"
      
      
      // getVersion needs a project object. During the firstSync this is not set yet
      def targetProject = firstSync ? nodeHelper.getProject("DEMO") : issue.project
      
      // lookup the version in the project and *add* it to the affectedVersions 
      issue.affectedVersions += nodeHelper.getVersion(targetVersionName,targetProject)


      Notice the peculiar '+='  in the last line of the code.  AffectedVersions is an array and you either convert the single version to an array (and assign) or add it to the existing.



      Let me know if this helps

        CommentAdd your comment...