Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Unable to set the custom field whille creating subtask using Script post function

Sadaf Jabin August 20, 2018

I am trying to automate the sub-task creation based on a number of checkbox fields(project requirement and impacted marketplaces). But every time I am landing on the same issue as below:

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2018-08-20 12:05:38,642 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2018-08-20 12:05:38,644 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: FIN-11, actionId: 21, file: <inline script>
com.atlassian.jira.exception.CreateException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:588)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssueObject(DefaultIssueManager.java:594)
	at com.atlassian.jira.issue.managers.RequestCachingIssueManager.createIssueObject(RequestCachingIssueManager.java:185)
	at com.atlassian.jira.issue.IssueManager$createIssueObject$1.call(Unknown Source)
	at Script115$_run_closure3$_closure5.doCall(Script115.groovy:77)
	at Script115$_run_closure3.doCall(Script115.groovy:55)
	at Script115.run(Script115.groovy:51)
Caused by: com.atlassian.jira.workflow.WorkflowException: Error occurred while creating issue. This could be due to a plugin being incompatible with this version of JIRA. For more details please consult the logs, and see: http://confluence.atlassian.com/x/3McB
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:766)
	at com.atlassian.jira.issue.managers.DefaultIssueManager.createIssue(DefaultIssueManager.java:580)
	... 6 more
Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to java.util.Collection
	at com.atlassian.jira.issue.customfields.impl.AbstractMultiCFType.createValue(AbstractMultiCFType.java:39)
	at com.atlassian.jira.issue.fields.ImmutableCustomField.createValue(ImmutableCustomField.java:693)
	at com.atlassian.jira.workflow.function.issue.IssueCreateFunction.execute(IssueCreateFunction.java:81)
	at com.opensymphony.workflow.AbstractWorkflow.executeFunction(AbstractWorkflow.java:1014)
	at com.opensymphony.workflow.AbstractWorkflow.transitionWorkflow(AbstractWorkflow.java:1407)
	at com.opensymphony.workflow.AbstractWorkflow.initialize(AbstractWorkflow.java:606)
	at com.atlassian.jira.workflow.OSWorkflowManager.createIssue(OSWorkflowManager.java:742)
	... 7 more

 

Please note that i am able to create the subtask when the subtask customfields are not being updated.Find my script below for your reference:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import java.util.List
import java.lang.Class
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.config.SubTaskManager
//import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.user.ApplicationUser
ComponentManager componentManager = ComponentManager.getInstance()
def applicationUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def constantManager = ComponentAccessor.getConstantsManager()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()

Issue parentIssue = issue

if (issue.getIssueType() == 'Sub-task')
 return

CustomField project_req = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Project Requirements? ")
CustomField mkpl = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impacted Marketplaces")
CustomField content_need_by_date = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Content Need By Date")
def optionsManager = ComponentAccessor.getOptionsManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
//def customField = customFieldManager.getCustomFieldObject(faveFruitFld.getFieldId())
def req_config = project_req.getRelevantConfig(parentIssue)
def options = optionsManager.getOptions(req_config)
def optionToSelect = options.find { it.value == "Editorial - Seller Central Announcement" }
def mkpl_config = mkpl.getRelevantConfig(parentIssue)
def mkpl_options = optionsManager.getOptions(mkpl_config)
def optionToSelect_mkpl = mkpl_options.find { it.value == "United States" }
//project_req.setFormValue(optionToSelect.optionId)
/*CustomField launch_Date = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("/Desired Launch Date/")*/

ArrayList list = new ArrayList();
ArrayList list_mkpl = new ArrayList();
def cur_req,cur_mkpl
list=(ArrayList)issue.getCustomFieldValue(project_req);
list_mkpl=(ArrayList)issue.getCustomFieldValue(mkpl);

/*issue.description=issue.getCustomFieldValue(project_req);*/
list.each{
    cur_req=it
            def value = ComponentAccessor.optionsManager.getOptions(project_req.getRelevantConfig(issue))?.find { it.toString() == it.toString()};

    list_mkpl.each{
        cur_mkpl=it
        issue.description=cur_mkpl
        String launch_Date_field=issue.description + " Desired Launch Date"
        CustomField launch_Date = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(launch_Date_field)
        issue.description=cur_req.toString() +","+ cur_mkpl.toString()
        MutableIssue newSubTask = issueFactory.getIssue()
        newSubTask.summary = parentIssue.summary+"_"+cur_req.toString() +"_"+ cur_mkpl.toString()
        newSubTask.description="this a test issue"
        newSubTask.issueTypeId = '5'
        newSubTask.setCustomFieldValue(project_req,optionToSelect.optionId)
                def value1 = ComponentAccessor.optionsManager.getOptions(mkpl.getRelevantConfig(issue))?.find { it.toString() == it.toString()};

        newSubTask.setCustomFieldValue(mkpl,optionToSelect_mkpl.optionId)
        newSubTask.setCustomFieldValue(content_need_by_date,parentIssue.getCustomFieldValue(content_need_by_date))
        newSubTask.setCustomFieldValue(launch_Date,parentIssue.getCustomFieldValue(launch_Date))
    //issue.description=parentIssue.getCustomFieldValue(launch_Date)
        /*newSubTask.project = issue.project*/
        newSubTask.setParentObject(issue)
           newSubTask.setProjectObject(issue.getProjectObject())
         def newIssueParams = ["issue" : newSubTask] as Map<String,Object>
        
        issueManager.createIssueObject('sadafjbn', newIssueParams)
         /*subTaskManager.createSubTaskIssueLink(issue, newSubTask, 'sadafjbn')*/
        subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, applicationUser);
// log.info "Issue with summary ${newSubTask.summary} created"
    }
}

 

Any help will be highly appreciated.Looking forward for your responses.

Thanks,
Sadaf Jabin

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Mark Markov
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.
August 20, 2018

Hello @Sadaf Jabin

What is your JIRA and Scriptrunner version?

Sadaf Jabin August 20, 2018

Hello @Mark Markov,

We are using JIRA 7.7.2 and Scriptrunner 5.4.12.

TAGS
AUG Leaders

Atlassian Community Events