Questions for Confluence license has expired.

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

Can't get data from subtask to be synced

 
1
0
-1

Hi there,


I am working on a solution for my client and I need some help.

At my client the following configuration is given:


System A

  • orders are stored in issues (an order is a collection of small development tasks, my client orders the implementation of these collections of tasks from various partners)
  • each order has a subtask to store sensitive financial data about the order (they use issue security to make sure that only special users can see the sensitive data)


System B

  • orders are stored in issues and sensitive financial data is stored on these issues as well (so there are no subtasks, everything is stored on the "main" issue)


My task is to configure a sync between these systems by syncing all data from system A to system B including the synchronization of the sensitive data from the subtask existing in system A to the "main" issue existing in system B.

Currently my solution is syncing only the two "main" issues (in system A and in system B), the subtask in system A is excluded from sync.

Using scriptrunner I successfully set up a trigger in system A to start a resync on the parent issue when something changes in the connected subtask in system A.

In the outgoing sync rule I wrote a groovy script to select correct subtask and get sensitive data (field value) stored on it. I stored this value in replica.customKeys (please see code below).
In the incoming rule I am attempting to get the value from replica.customKeys.


My problem is that is seems like I do not get the actal value from the customfield of the subtask, instead I get a previously stored value. Seems like it is cached somehow.


I attached my sync rules, I have cleaned them to only contain the code related to this problem.

Please help me with this problem. Any recommendations are for a solution are welcome.


Many thanks!


Cheers,
Gabor


outgoing rule
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager

CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager) 
Issue issueObj = issueManager.getIssueObject(issue.key)

replica.customKeys.ha = "N/A"

issueObj.getSubTaskObjects()?.each{it ->
  if (it.getIssueType()?.getId() == "10301"){ 
    // "Sub-task" - we only have one subtask per issue of this type 
    replica.customKeys.ha = getCFValue(issueManager.getIssueObject(it.key), 11600).toString() ?: "N/A" 
  }
}

def getCFValue (Issue issue, Long cfId) {
  issue.getCustomFieldValue(customFieldManager.getCustomFieldObject(cfId))
}
incoming rule
issue.summary = replica.summary + " – " + replica.customKeys?.ha
log.error ("value we get - " + replica.customKeys?.ha)
  1. Ariel Aguilar

    Hi Gabor,

    I see on the outgoing script, you are defining getCFValue after it is used. Shouldn't it be defined before?

    Kind regards,

    Ariel

  2. Gabor Nagy

    Hi Ariel,


    I think getCFValue is ok there, it is working.


    I attach my actual scripts (I have simplified them as I can) in case you can test it in your environment.


    In my test I had the following data in my systems:

    • System B issue (POT-121) and System A issue (TETETE-43) are already in sync.
    • I have a Sub-task under TETETE-43 with issue key TETETE-44.
    • TETETE-44 sub-task has a custom field called "_ha" (field id: 11600, value: 4)


    My outgoing rule:

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.IssueManager
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.CustomFieldManager
    
    if (issue.project.key in ["POT"]) { // B -> A
        replica.customKeys.projectKey = "TETETE"
        replica.customKeys.typeName = "New Feature"
    
        replica.key            = issue.key
        replica.type           = issue.type
        replica.summary        = issue.summary
    
    } else { // A -> B
        log.error "\n\n----------------- OUTGOING TETETE -> POT ------------------\n\n"
        
        IssueManager issueManager = ComponentAccessor.getComponent(IssueManager)
        CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
        
        Issue issueObj = ComponentAccessor.getComponent(IssueManager).getIssueObject(issue.key)
    
        issueObj.getSubTaskObjects()?.each{it ->
            if (it.getIssueType()?.getId() == "10301") { // "Sub-task"
                replica.customKeys.ha = issueManager.getIssueObject(it.key)
                                            .getCustomFieldValue(customFieldManager.getCustomFieldObject(11600)) // _ha field ID
            }
        }
    
        log.error "_ha value: " + replica.customKeys."ha".toString()
        
        log.error "\n\n----------------- / OUTGOING TETETE -> POT ------------------\n\n"
    }
    
    



    My incoming rule:

    if (replica.customKeys?.projectKey == "TETETE"){ // B -> A
        if(firstSync){
            issue.projectKey = replica.customKeys.projectKey
            issue.typeName = nodeHelper.getIssueType(replica.customKeys.typeName, issue.projectKey)?.name ?: "New Feature"
        }
    
        issue.summary = replica.summary
    
    } else { // A -> B
        if(!firstSync){
    
        }
        
    }
    



    If I change any field on TETETE-43 issue, my sync rule run and I see the following in my log - "_ha" field value is not ok, the value is outdated:


    2021-08-11 07:38:29,150+0200 http-nio-8080-exec-18 INFO admin 458x866783x1 19kefnu 10.196.6.4,127.0.0.1 /secure/AjaxIssueAction.jspa [c.exalate.trigger.SyncListener] The status for the issue BasicIssueKey{@id=`12719`, @urn=`TETETE-43`, @entityType=`issue`} is the same both in the issue and in the issueManager
    2021-08-11 07:38:29,198+0200 http-nio-8080-exec-18 INFO admin 458x866783x1 19kefnu 10.196.6.4,127.0.0.1 /secure/AjaxIssueAction.jspa [c.a.jira.index.MonitoringIndexWriter] [lucene-stats] flush stats: snapshotCount=3, totalCount=7628, periodSec=1045, flushIntervalMillis=348595, snapshotNoDocs=0, totalNoDocs=0, indexDirectory=/var/atlassian/application-data/jira/caches/indexesV1/issues, indexWriterId=com.atlassian.jira.index.MonitoringIndexWriter@5d76fd66, indexDirectoryId=MMapDirectory@/var/atlassian/application-data/jira/caches/indexesV1/issues lockFactory=org.apache.lucene.store.NativeFSLockFactory@41cbcdeb
    2021-08-11 07:38:29,203+0200 http-nio-8080-exec-18 DEBUG admin 458x866783x1 19kefnu 10.196.6.4,127.0.0.1 /secure/AjaxIssueAction.jspa [c.e.n.hubobject.v1_3.NodeHubObjectConversionService] jiraAssignee is not present for issue `TETETE-43`
    2021-08-11 07:38:29,223+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.eventhandler.IssueEventHandlerService] Received Jira issue event for an exalated issue: `TETETE-43`.
    2021-08-11 07:38:29,228+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: creating a replica for the issue `BasicIssueKey{@id=`12719`, @urn=`TETETE-43`, @entityType=`issue`}`, connection `POT_to_TETETE`
    2021-08-11 07:38:29,240+0200 pool-260-thread-1 INFO admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] #createHubReplica: preparing to run the data filter processor to create a replica for the issue `TETETE-43`, connection `POT_to_TETETE`
    2021-08-11 07:38:29,252+0200 pool-260-thread-1 INFO admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] Getting the data filter processor parameters for issue `TETETE-43`
    2021-08-11 07:38:29,252+0200 pool-260-thread-1 INFO admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] Executing the data filter for the issue `TETETE-43`, connection `POT_to_TETETE`
    2021-08-11 07:38:29,298+0200 pool-260-thread-1 ERROR admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] 
        
        ----------------- OUTGOING TETETE -> POT ------------------
        
        
    2021-08-11 07:38:29,305+0200 pool-260-thread-1 ERROR admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] _ha value: 3
    2021-08-11 07:38:29,305+0200 pool-260-thread-1 ERROR admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] 
        
        ----------------- / OUTGOING TETETE -> POT ------------------
        
        
    2021-08-11 07:38:29,306+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [com.exalate.script] The replica's comments for issue BasicIssueKey{@id=`12719`, @urn=`TETETE-43`, @entityType=`issue`} after executing the data filter are: []
    2021-08-11 07:38:29,317+0200 pool-260-thread-1 INFO admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.exalate.replication.EventLifecycleHelper] Creating sync event for POT_to_TETETE and local replica: 1544 for issue BasicIssueKey{@id=`12719`, @urn=`TETETE-43`, @entityType=`issue`}. Twin trace: 152. Remote twin trace: 151
    2021-08-11 07:38:29,321+0200 pool-260-thread-1 INFO admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: created the syncEvent `609` for the issue `TETETE-43` and connection `POT_to_TETETE`
    2021-08-11 07:38:29,321+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: going to attach blob metadata list of size `0` to sync event `609`
    2021-08-11 07:38:29,321+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: going to attach local traces list of size `0` to sync event `609`
    2021-08-11 07:38:29,321+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: inferring and setting trace actions for `0` traces` for sync event `609`
    2021-08-11 07:38:29,322+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: attaching `0` local traces with inferred trace actions ` to sync event `609`
    2021-08-11 07:38:29,323+0200 pool-260-thread-1 DEBUG admin 1256x864344x1 57ypug 10.196.6.4,127.0.0.1 /secure/WorkflowUIDispatcher.jspa [c.e.r.out.schedule.EventSchedulerService] #scheduleSyncEvent: going to publish `SYNC_EVENT` notification for sync event `609`
    2021-08-11 07:38:32,073+0200 pool-261-thread-1 DEBUG admin 1255x864337x1 57ypug 10.196.6.4,127.0.0.1 /rest/plugins/1.0/com.exalate.jiranode-key [c.e.replication.out.EventProcessorService] Preparing UPDATE sync event for connection POT_to_TETETE and twin trace 152
    2021-08-11 07:38:32,092+0200 pool-261-thread-1 INFO admin 1255x864337x1 57ypug 10.196.6.4,127.0.0.1 /rest/plugins/1.0/com.exalate.jiranode-key [c.e.replication.out.EventProcessorService] The syncEvent for the issue `TETETE-43` and connection `Connection{@name=`POT_to_TETETE`}` would not be processed - the new replica is the same as the old one. Will schedule cleanup for sync event
    2021-08-11 07:38:32,101+0200 pool-261-thread-1 DEBUG admin 1255x864337x1 57ypug 10.196.6.4,127.0.0.1 /rest/plugins/1.0/com.exalate.jiranode-key [c.exalate.replication.ReplicaLifecycleHelper] #deleteAndCleanUp: deleting the replica `1544` for the issue `BasicIssueKey{@id=`12719`, @urn=`TETETE-43`, @entityType=`issue`}`



    If I run the following script in script console, I get the correct "_ha" value


    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.IssueManager
    import com.atlassian.jira.issue.CustomFieldManager
    
    IssueManager issueManager = ComponentAccessor.issueManager
    CustomFieldManager customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
    
    
    Issue issue = issueManager.getIssueObject("TETETE-43")
    
    def result
    
    issue.getSubTaskObjects()?.each{it ->
        if (it.getIssueType()?.getId() == "10301") { // "Sub-task"
            result = issueManager.getIssueObject(it.key).getCustomFieldValue(customFieldManager.getCustomFieldObject(11600)) // "_ha" field
        }
    }
    
    return result
    
    
    // it returns result: 4




    Thanks for your help!

CommentAdd your comment...