...
Setting Content of Message++
...
Field with Script Runner
...
Following Script will set content of Message++ field to a table constructed using a template and fields from issue.
You can find JavaDoc of our API here.
Code Block | ||||
---|---|---|---|---|
| ||||
import com.deniz.jira.cf.imp.message.MessageConfigManager; import com.onresolve.scriptrunner.runner.customisers.PluginModule; import com.onresolve.scriptrunner.runner.customisers.WithPlugin; import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.Issue; import java.text.SimpleDateFormat; @WithPlugin("com.deniz.jira.customfields") @PluginModule MessageConfigManager messageConfigManager; def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager) def issue = event.issue as Issue; def body=""" <div> <div id="header"> <p>As the Project's Investment Sponsor, please <a href="http://localhost:2990/jira/secure/CommentAssignIssue!default.jspa?action=101&id=${issue.id}" target="_blank">Appoved</a> the project closure or request <a href="http://localhost:2990/jira/secure/CommentAssignIssue!default.jspa?action=71&id=${issue.id}" target="_blank">Rework</a>. </p> <div> <div id="summary-table"> <h2>${issue.summary}</h2> <table> <tr> <th bgcolor="#DCDCDC">Reporter</th> <th bgcolor="#DCDCDC">Project Manager</th> <th bgcolor="#DCDCDC">Business Case Owner</th> <th bgcolor="#DCDCDC">End Date</th> <th bgcolor="#DCDCDC">Status</th> <th bgcolor="#DCDCDC">CRB Closure</th> </tr> <tr> <td>${issue.reporter?.displayName}</td> <td>${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Project Manager"))?.displayName}</td> <td>${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Business Case Owner"))?.displayName}</td> <td>${new SimpleDateFormat("d MMM yyyy").format(issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("End date")))}</td> <td>${issue.status.name}</td> <td>${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("CRB Closure"))}</td> </tr> </table> </div> </div> """ messageConfigManager.save(11600L, "error", "Body is set by Script Runner on Message++", body, false); |
Code Block | ||||
---|---|---|---|---|
| ||||
import com.deniz.jira.cf.imp.ss.*;
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue;
import java.text.SimpleDateFormat;
import com.atlassian.activeobjects.external.ActiveObjects
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.atlassian.jira.issue.customfields.option.*;
import com.deniz.jira.cf.imp.message.*;
import org.apache.log4j.Logger
import org.apache.log4j.Level
//Set Log level for Debugging
def log = Logger.getLogger("com.onresolve.jira.groovy")
log.setLevel(Level.DEBUG)
@WithPlugin("com.deniz.jira.customfields")
@PluginModule
ExtraOptionInformationManagerFactory factory;
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def issue = event.issue as Issue;
def customersCF = customFieldManager.getCustomFieldObjectByName("Customers");
def customFieldValue = issue.getCustomFieldValue(customersCF); //this returns an array com.atlassian.jira.issue.customfields.option.Option
def fieldConfig = customersCF.getRelevantConfig(issue);
def extraOptionInformationManager = factory.get(customersCF, fieldConfig, true);
customFieldValue.each { option ->
def extraInfo = extraOptionInformationManager.getOption(((Option) option).getOptionId()); //ExtraOptionInformation
log.debug("Description:" + extraInfo.getDescription());
}
|