/
Java API for Multi Cascade

Java API for Multi Cascade

To use Multicascade Java API, you need to use an object of com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager class. You can get it using the following code in your Groovy script:

Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def tgeGridDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass);



MulticascadeDataManager has the following methods:





readMultiCascadeData method
@param customFieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @return a map that contains the multicascade's level name as the key and the respective selected value as the value @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException Map<String, String> readMultiCascadeData(Long customFieldId, Long issueId)





readMultiCascadeData example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // read Multicascadedata PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def resultMap = null; try { resultMap = multicascadeDataManager.readMultiCascadeData(multicascadeCustomFieldId, issueId); result.append(resultMap.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be retrieved: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be retrieved: " + e.getMessage() + "\n"); } return result.toString()



editMultiCascadeData method
@param customfieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @param values - a map that holds the name of the level to edit as a key and the new value to be assigned as the value @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException @throws MultiCascadeInvalidInputException void editMultiCascadeData(Long customfieldId, Long issueId, Map<String, String> values)





editMultiCascadeData example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // edit Multicascade data PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def resultMap = null; Map<String, Object> dataMap = new HashMap<String, String>(); dataMap.put("issuetype", "10002"); dataMap.put("user", "admin"); try { multicascadeDataManager.editMultiCascadeData(multicascadeCustomFieldId, issueId, dataMap) resultMap = multicascadeDataManager.readMultiCascadeData(multicascadeCustomFieldId, issueId); result.append(resultMap.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be edited: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be edited: " + e.getMessage() + "\n"); } return result.toString()



resetMultiCascadeLevel method
@param customFieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @param level - the name of the level to reset @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException @throws MultiCascadeInvalidInputException void resetMultiCascadeLevel(Long customFieldId, Long issueId, String level)



resetMultiCascadeLevel example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // reset a list of Multicascade levels PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def resultMap = null; List levels = new ArrayList() levels.add("issuetype") levels.add("user") try { multicascadeDataManager.resetMultiCascadeLevels(multicascadeCustomFieldId, issueId, levels) resultMap = multicascadeDataManager.readMultiCascadeData(multicascadeCustomFieldId, issueId); result.append(resultMap.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage() + "\n"); } return result.toString()





resetMultiCascadeLevels method
@param customFieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @param levels - a list with the name of the levels to be reset @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException @throws MultiCascadeInvalidInputException void resetMultiCascadeLevels(Long customFieldId, Long issueId, List<String> levels)





resetMultiCascadeLevels example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // reset a list of Multicascade levels PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def resultMap = null; List levels = new ArrayList() levels.add("issuetype") levels.add("user") try { multicascadeDataManager.resetMultiCascadeLevels(multicascadeCustomFieldId, issueId, levels) resultMap = multicascadeDataManager.readMultiCascadeData(multicascadeCustomFieldId, issueId); result.append(resultMap.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage() + "\n"); } return result.toString()





resetAllMultiCascadeLevels method
@param customFieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException @throws MultiCascadeInvalidInputException void resetAllMultiCascadeLevels(Long customFieldId, Long issueId)





resetAllMultiCascadeLevels example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // reset all Multicascade levels PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def resultMap = null; try { multicascadeDataManager.resetAllMultiCascadeLevels(multicascadeCustomFieldId, issueId) resultMap = multicascadeDataManager.readMultiCascadeData(multicascadeCustomFieldId, issueId); result.append(resultMap.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " data cannot be reset: " + e.getMessage() + "\n"); } return result.toString()





readMultiCascadeLevelOptions method
@param customFieldId - the Multicascade's customfield ID @param issueId - the ID of the relevant issue @param levelName - the name of the level to read the available options from @return a list of the options available for the level to choose as its value @throws MultiCascadeNotFoundException @throws MultiCascadePermissionDeniedException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException @throws MultiCascadeInvalidInputException List<String> readMultiCascadeLevelOptions(Long customfieldId, Long issueId, String levelName)





readMultiCascadeLevelOptions example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // read available options for the level 'user' PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def optionsForUser = null; try { optionsForUser = multicascadeDataManager.readMultiCascadeLevelOptions(multicascadeCustomFieldId, issueId, "user") result.append(optionsForUser.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " cannot read options: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " cannot read options: " + e.getMessage() + "\n"); } return result.toString()





readMultiCascadeLevels method
@param customfieldId - the Multicascade' customfield ID @param issueId - the ID of the relevant issue @return a list of names of the levels available for the given multicascade field @throws MultiCascadePermissionDeniedException @throws MultiCascadeNotFoundException @throws MultiCascadeWrongCFTypeException @throws MultiCascadeUserNotAuthorisedException List<String> readMultiCascadeLevels(Long customfieldId, Long issueId)





readMultiCascadeLevels example code
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.plugin.PluginAccessor; import org.apache.log4j.Logger import org.apache.log4j.Level Logger log = Logger.getLogger("com.idalko.scripts"); log.setLevel(Level.DEBUG); // get an issue IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class); Issue issue = issueManager.getIssueObject("TEST-1"); Long issueId = issue.getId() // get Multicascade custom field CustomFieldManager customFieldManager = ComponentAccessor.getOSGiComponentInstanceOfType(CustomFieldManager.class); CustomField multicascadeCustomField = customFieldManager.getCustomFieldObjectsByName("Multic").get(0); Long multicascadeCustomFieldId = multicascadeCustomField.getIdAsLong(); // read the levels of Multicascade PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor(); // ScriptRunner could show a validation error at this point showing that the class could not be resolved. // Just ignore it. It resolves it at the run time. Class dataManagerClass = pluginAccessor.getClassLoader().findClass("com.idalko.jira.plugins.igrid.api.data.MultiCascadeDataManager"); def multicascadeDataManager = ComponentAccessor.getOSGiComponentInstanceOfType(dataManagerClass); StringBuilder result = new StringBuilder(); def levels = null; try { levels = multicascadeDataManager.readMultiCascadeLevels(multicascadeCustomFieldId, issueId) result.append(levels.toString()) } catch (Exception e) { log.debug("Multicascade ID=" + multicascadeCustomFieldId + " cannot read options: " + e.getMessage()) result.append("Multicascade ID=" + multicascadeCustomFieldId + " cannot read options: " + e.getMessage() + "\n"); } return result.toString()