Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Filling fields via scripting affects uninvolved issues that were cloned?

Deleted user January 6, 2020

Hello,

in our "change management" process we normally raise an issue from type "suggestion" which gets cloned into a "request" issuetype and finally gets cloned into a "change" type issue. To track several fields like "release date" and stuff we implemented a script fragment panel and a script listener which gets displayed in the "request" issuetype and shows relevant data from the "change" issuetype.

Problem: In our issue search and furthermore our gadgets and reporting dashboards the initial issuetype "suggestions" now also shows data in fields like "release date". But these fields are only configured and relevant for "changes" and get synchronized backwards to the script runner web panel displayed in "requests". We use the following script to fill the web panel fragment:

ApplicationUser superuser = ComponentAccessor.userManager.getUserByName("superuser")

def issueManager = ComponentAccessor.getIssueManager()

Date date = new Date();

SimpleDateFormat dateFormat = new SimpleDateFormat("DD/MM/YYYY");
String formattedDate = dateFormat.format(date);

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

List<IssueLink> inwardLinks = issueLinkManager.getInwardLinks(event.issue.getId())

// CustomField implementationIssue = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11572");
CustomField implementationStatus = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11601");
CustomField implementationManager = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12600");
CustomField readyPlan = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12605");
CustomField readyIs = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12604");
CustomField releasePlan = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12606");
CustomField releaseIs = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12607");
CustomField release = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11400");
CustomField changeManager = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10315");

for (IssueLink issueLink : inwardLinks){
Issue destination = issueLink.getDestinationObject()
Issue source = issueLink.getSourceObject()
MutableIssue mutableSource = source as MutableIssue
MutableIssue mutableDestination = destination as MutableIssue
if (issueLink.issueLinkType.name == "link" && source.getProjectId() == 10100L && destination.getProjectId() != 10100L) {
log.debug("ID parent: " + mutableSource.getId())
log.debug("Key Parent: " + mutableSource.getKey())

mutableSource.setCustomFieldValue(implementationStatus , destination.getStatus().getSimpleStatus().getName().toString())
mutableSource.setCustomFieldValue(implementationManager , destination.getCustomFieldValue(changeManager));
mutableSource.setCustomFieldValue(readyPlan, destination.getCustomFieldValue(readyPlan ))
mutableSource.setCustomFieldValue(readyIs, destination.getCustomFieldValue(readyIs))
mutableSource.setCustomFieldValue(releasePlan, destination.getCustomFieldValue(releasePlan))
mutableSource.setCustomFieldValue(releaseIs, destination.getCustomFieldValue(releaseIs))
mutableSource.setCustomFieldValue(release, destination.getCustomFieldValue(release))

issueManager.updateIssue(superuser, mutableSource, EventDispatchOption.ISSUE_UPDATED, false)
issueManager.updateIssue(superuser, mutableDestination, EventDispatchOption.ISSUE_UPDATED, false)

log.debug("Ready")
} else {
log.debug("Project not BRM")
}
}
}

 

1 answer

1 accepted

0 votes
Answer accepted
Marc Minten (EVS)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2020

Just add a check on issue type where you check already link type and project ?

Unfortunately, for the issues where the values are already copied by the script above, the values will remain...

Deleted user January 8, 2020

Thanks for your reply. I added some check in the if clause which looks like the follwing:

if (issueLink.issueLinkType.name == "link" && source.issueType.name in ["Request"] && destination.getProjectId() != 10100L)

 It's still copying these values to our initial "suggestion" issue type. Am I mising something? Should I check for issuetype in my for loop before? Or maybe my source.issue calls for all sources in the link hierarchy not only the "request"?

Marc Minten (EVS)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2020

First : your code is really hard to read (no indentations at all).

What links do exist between your Suggestion, Request and Change issues ? You talk about "cloning" and you check in your script on a link type "link" ???

What do you find in your log files as result of the log.debug statements in your script (assuming you activated DEBUG level logging) ?

Deleted user January 8, 2020

Sorry for that, but the style gets lost when I copy my blocks into these text fields here.

Normal issue links, don't know what it's called in english but in german it would be "Verknüpfung".

I added 2 more logging statements (Issue Key and LinkList):

2020-01-08 12:06:38,622 DEBUG [groovy.PostFunction]: Issue: ERP-48

2020-01-08 12:06:38,623 DEBUG [groovy.PostFunction]: [com.atlassian.jira.issue.link.IssueLinkImpl@4638ee81[id=13832,sourceId=20838,destinationId=20839,issueLinkType=10300], com.atlassian.jira.issue.link.IssueLinkImpl@5e757180[id=13831,sourceId=20837,destinationId=20839,issueLinkType=10300]] 2020-01-08 12:06:38,625 DEBUG [groovy.PostFunction]: ID parent: 20838 2020-01-08 12:06:38,626 DEBUG [groovy.PostFunction]: Key Parent: BRM-25

 Im confused since the issueLink shows 2 Links from our request (ID 20838) to our change (ID 20839) and from our suggestion (ID 20837) to our change (ID 20839). Maybe thats the problem?

Another problem is, that the last 2 logging statements ("Ready" / Project not BRM")  won't get reached and the issues might not get updated. You have and clue about that?

Marc Minten (EVS)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2020

Hmm, its really hard to follow when mixing logging of issue keys and issue ids, and not knowing where the log results come from (where were they added in the code ?)

What is ERP-48 ? Suggestion ? Request ? Change ?

And BRM-25 ?

Can you resend your (correctly formatted) code with the debug statements. And for the debug info: explain for what (type of) issue the debug info was generated.

You can (easily) validate the existing links in the Jira UI ? What links do exist between these issues ?

Deleted user January 8, 2020

Ok here is the code block:

def log = Logger.getLogger "com.onresolve.jira.groovy.PostFunction"
log.setLevel(Level.DEBUG)

log.debug("1. Issue: " + event.issue.key) // Issue triggering the script

ApplicationUser superuser = ComponentAccessor.userManager.getUserByName("superuser")

def issueManager = ComponentAccessor.getIssueManager()

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()

List<IssueLink> inwardLinks = issueLinkManager.getInwardLinks(event.issue.getId())

CustomField umsetzungsStatus = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11601");
CustomField umsetzungsAnsprechpartner = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12600");
CustomField bereitstellungZurAbnahmePlan = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12605");
CustomField bereitstellungZurAbnahmeIst = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12604");
CustomField releasedatumPlan = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12606");
CustomField releasedatumIst = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12607");
CustomField release = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_11400");
CustomField planTest = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12505");
CustomField istTest = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12506");
CustomField planProd = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12507");
CustomField istProd = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12508");
CustomField changeManager = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10315");

log.debug(2. "LinkList": inwardLinks) // Gives list of links to the above issue

for (IssueLink issueLink : inwardLinks){

Issue destination = issueLink.getDestinationObject()
Issue source = issueLink.getSourceObject()
MutableIssue mutableSource = source as MutableIssue
MutableIssue mutableDestination = destination as MutableIssue

if (issueLink.issueLinkType.name == "Verknüpfung" && source.issueType.name in ["Request"] && destination.getProjectId() != 10700l) {

log.debug(3. "ID parent: " + mutableSource.getId()) // ID of parent
log.debug(4. "Key parent: " + mutableSource.getKey()) // KEY of parent
log.debug(5. "ID child: " + mutableDestination.getId()) // ID child
log.debug(6. "KEY child: " + mutableDestination.getKey()) // KEY child

mutableSource.setCustomFieldValue(umsetzungsStatus,destination.getStatus().getSimpleStatus().getName().toString())
mutableSource.setCustomFieldValue(umsetzungsAnsprechpartner,destination.getCustomFieldValue(changeManager));
mutableSource.setCustomFieldValue(bereitstellungZurAbnahmePlan,destination.getCustomFieldValue(bereitstellungZurAbnahmePlan))
mutableSource.setCustomFieldValue(bereitstellungZurAbnahmeIst,destination.getCustomFieldValue(bereitstellungZurAbnahmeIst))
mutableSource.setCustomFieldValue(releasedatumPlan,destination.getCustomFieldValue(releasedatumPlan))
mutableSource.setCustomFieldValue(releasedatumIst,destination.getCustomFieldValue(releasedatumIst))
mutableSource.setCustomFieldValue(release,destination.getCustomFieldValue(release))

issueManager.updateIssue(superuser, mutableSource, EventDispatchOption.ISSUE_UPDATED, false)
issueManager.updateIssue(superuser, mutableDestination, EventDispatchOption.ISSUE_UPDATED, false)

log.debug(7. "Fertig")
} else {
log.debug(8. "Project not BRM")

}
}

I have no idea how to format this better in here. Can't use space, tab and stuff in these code blocks nor do I know how to avoid these splitting lines. Maybe I'm too dumb.

2020-01-08 13:27:37,870 DEBUG [groovy.PostFunction]: 1. Issue: Change-61

2020-01-08 13:27:37,871 DEBUG [groovy.PostFunction]: 2. LinkList: com.atlassian.jira.issue.link.IssueLinkImpl@63243e72[id=13838,sourceId=20844,destinationId=20845,issueLinkType=10300], com.atlassian.jira.issue.link.IssueLinkImpl@2d45f945[id=13837,sourceId=20843,destinationId=20845,issueLinkType=10300]
2020-01-08 13:27:37,872 DEBUG [groovy.PostFunction]: 3. ID parent: 20844 2020-01-08 13:27:37,872 DEBUG [groovy.PostFunction]: 4. KEY parent: request 2020-01-08 13:27:37,872 DEBUG [groovy.PostFunction]: 5. ID Child: 20845 2020-01-08 13:27:37,872 DEBUG [groovy.PostFunction]: 6. KEY Child: change

 I hope it gets clearer now. As the logging shows, parent would be the "request" and "child" the change issue. But the linkList shows 2 links, request (ID 20844) -change and suggestion (ID 20843) -change

Marc Minten (EVS)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2020

Yes, thats what the debug says:

- there is a link from the Request to the Change Issue

- and there is a link from the Suggestion to the Change Issue

You should see these links in your Jira UI. Correct ?

Where did you found the log info ? It seems it is truncated. You miss the 7. "Fertig" info, and... probably the info generated by treating the second link, updating the Suggestion issue...

Other strange things :

log.debug(7. "Fertig")

does not seem to be correct syntax to me (the 7. outside the quotes). Did it run like that ?

Also the debug shows [groovy.PostFunction] : where does this come from ? Your script is not a Postfunction but a listener ? right ?

Deleted user January 8, 2020

Yes I see these links in the issue details / Issue link section. It's just awkward for me, that the logged list just shows those 2 links but where is the 3rd link from suggestion->request?

Yeah the syntax was wrong so it didn't run but fixed it now.

[groovy.PostFunction] comes from the Logger I initialize on top of the script. Just used one of the loggers of the System -> Profiling / Logging Section.

But I still don't get why these customfields, which i write on in the IF section also show up in the issue search for type suggestion. I mean I just want them to be shown in the change itself (ofc, cause I configured them there in screens and stuff) and in the request (therefore I implemented a web panel). I mean the logging says KEY parent: request and KEY child: change so why is he writing it also to the suggestion?

Marc Minten (EVS)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2020

Why would you see a third link from suggestion->request ? This script is executed on a "change" issue, and you ask all the links to that issue. So you will never see links between these other issues...

What do you mean with "... show up in the issue search for type suggestion..." . These fields probably exist for all issue types, so you can search on them ... ?

But if you also have a link between the Request and the Suggestion issue, your script will update the Suggestion issue ! Correct ?

Deleted user January 29, 2020

Sorry, didn't respond in time since I wasn't in office. Turned ouut that another script existed on the instance, which did the exact same thing without focusing on issuetypes, so after I changed that sript, everything works fine now.

So focusing on "request" and "change" issuetypes in the if clause solved it finally.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events