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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,456,571
Community Members
 
Community Events
176
Community Groups

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

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

0 votes

Hello @Sadaf Jabin

What is your JIRA and Scriptrunner version?

Hello @Mark Markov,

We are using JIRA 7.7.2 and Scriptrunner 5.4.12.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events