Hi,
I started developing scripts in JIRA server 6.2.4, using the groovy scriptrunner plugin.
I want to populate a custom field (multi-line text - id: customfield_11170) with data from other custom fields on the "create issue"-screen, so that the populated field shows up on the "view issue"-screen.
When adding the following script code to a "invisible" scripted field placed on "create issue"-screen, all happens as supposed :
_______________________________________________
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
// getting related issue
MutableIssue myIssue = issue
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
// retrieving values from custom fields
// summary
String summary = myIssue.summary
//date
CustomField dateField = customFieldManager.getCustomFieldObject("customfield_10874")
String date = myIssue.getUpdated()
// assignee
CustomField assigneeField = customFieldManager.getCustomFieldObject("assignee")
String currentAssignee = myIssue.getAssignee().getName()
// correspondence category
CustomField categoryField = customFieldManager.getCustomFieldObject("customfield_10780")
String category = myIssue.getCustomFieldValue(categoryField)
// correspondence field "from"
CustomField vonField = customFieldManager.getCustomFieldObject("customfield_10871")
String von = myIssue.getCustomFieldValue(vonField)
// correspondence field "to"
CustomField zuField = customFieldManager.getCustomFieldObject("customfield_10872")
String zu = myIssue.getCustomFieldValue(zuField)
// predefined table header -> gets to be a "table"
String header = "||Datum||Name||Kategorie||von||zu||Zusammenfassung||\n"
// concatenating new table row data -> gets to be a "table row" to add to table
String newValue = header + "|" + date + "|" + currentAssignee + "|" + category + "|" + von + "|" + zu + "|" + summary + "|\n"
// updating value in custom field "short description" (customfield_11170)
if(summary != null){
CustomField dstSummaryField = customFieldManager.getCustomFieldObject("customfield_11170")
IssueChangeHolder ich = new DefaultIssueChangeHolder()
ModifiedValue mv = new ModifiedValue("",newValue)
dstSummaryField.updateValue(null,myIssue,mv,ich)
}
return newValue // not necessary, could be null, the cripted field does not have to be populated itself
________________________________________________________
so, THAT works. The table is generated and populated.
My Problem:
Adding a "similar script" to ANOTHER scriptedfield ONLY placed on the another screen "modify issue" (transition screen, so each scripted field is on ONE transition screen) results in executing the first script to, but the first one is placed on the "create issue screen", and I don't know why it executes on the second transition, too!
I thought, placing ONE scripted field to ONE screen only results in executing the related script ONLy on this transition and not everytime...?!??
So I decided to separate both script functionalities to place them each "as a postfunction" to the transitions WHERE they should execute. -> script1 for create-issue-transition and script2 for modify-issue-transition.
But placing script1 (above) as a postfunction doesn't seem to do anything, the result is "no String in customfield_11170, so -> no table generated.
What do I understand wrong on using the scripted fields or using postfunctions?
Anyone out ther, who can help.
Thanks alot.
Regard,
Alexander