customField not being update on Advance Roadmaps for JIRA server 8
Asked by mark.lamport:

Hi,

I have Scriptrunner script that reads a an Epic does a calculation and writes to a custom field in the Epic. This script gets read when epic is viewed

The custom field works gets updated in the epic correctly, however when I use the custom field in a Roadmap plan, it never updates unless I go into the field in roadmaps change the value and click Review. For the benefit of testing I have set the CustomField as Text and Free Text searchable.

My code snippet as follows:

```
if (mIssue.issueTypeObject.name == "Epic") {
    CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
    CustomField customField = customFieldManager.getCustomFieldObject(EpicTotalOriginalEstimateField)
    def issueManager = ComponentAccessor.getIssueManager()
   // def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()


    if (customField != null) {
        //def changeHolder = new DefaultIssueChangeHolder()
        // Double db = daysForEpic
        String db = ""+daysForEpic
        mIssue.setCustomFieldValue(customField, daysForEpic)
        customField.updateValue(null, mIssue, new ModifiedValue(cfieldValue, db),changeHolder)
        //MutableIssue issueMute = issueMger.getIssueObject("LS-11050") as MutableIssue
        //issueMute.setCustomFieldValue(customField, "100")
        //ComponentAccessor.getIssueManager().updateIssue(user, issueMute, EventDispatchOption.ISSUE_UPDATED, false)
        // issueMger.updateIssue(user, mIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
     }
```

I have called both setCustomFieldValue and updateValue

If I call updateIssue (as commented out) it kills my jira server. We are doing this because of the limitations of Advance Roadmaps that cant display calculated Custom fields.

I would appreciate any help in this.

Thanks,

-Mark


Answers:
author: Tomislav Nikolic
body: [@mark.lamport](/t5/user/viewprofilepage/user-id/4249920) I've found that if you send an IssueEvent through EventPublisher, Roadmaps will update the value in the plan.  

```
eventPublisher.publish(new IssueEvent(
        issueToUpdate,
        Collections.singletonMap("someIgnoreEventFlag", true),
        null, EventType.ISSUE_UPDATED_ID));
```

It might be a good idea to have this Collections.singletonMap("someIgnoreEventFlag", true),

that you can check in your own event listeners and decide not to react to them (otherwise you could get an infinite loop kind of thing happening). You can do that with

```
if(issueEvent.getParams() != null && issueEvent.getParams().containsKey("someIgnoreEventFlag")) return;
```

In your event listeners.

...

The downside to this solution I guess is there are other apps, other than roadmaps, that are going to get triggered, and in my case I don't need to neccessarily change the value, but rather have Roadmaps sync the value on first run, so other apps will react to no change. What are the implications of that, depends on other apps that are installed, so no way of knowing what the consequences would be.


author: Tomislav Nikolic
body: I suspect it's because the event is not being dispatched. I have similar code, and seems like updating with the code that you have commented out, and dispatching EventDispatchOption.ISSUE_UPDATED event, triggers something in Roadmaps to update the value in the plan.

For me it's problematic because I don't want to dispatch the event :D


Tags: advanced-roadmaps

custom-field

scriptrunner