Script function failed on Automation for Jira rule:IllegalArgumentException: wrong number of argumen

Mouna Hammoudi
Contributor
October 27, 2023

I am trying to use the HAPI API for Scriptrunner and I am getting the following error: enter image description here

My code is very simple, I am using the following:

         Collection < ProjectComponent > updatedComponentList = issue.getComponents()
         updatedComponentList.removeAll(component)

            issue.set {
                 setComponents(updatedComponentList)
            }

I have found the syntax under this link: https://docs.adaptavist.com/sr4js/latest/hapi/update-issues

Here is my whole code if needed:

package SuperFeature

import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.label.LabelManager
import SuperFeature.Configuration_SuperFeature
import com.adaptavist.hapi.jira.issues.delegate.AbstractIssuesDelegate
def log = Logger.getLogger('atlassian-jira.log')
List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()



    int componentSize = issue.getComponents().size()

    int generatedIssuesCounter= 0
     for (ProjectComponent component: issue.getComponents()) {
                      String componentName = component.getName()
                    def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
                    def projectName = componentName.substring(0, componentName.indexOf("-"))



                        if(Configuration_SuperFeature.projectNames.contains(projectName)){



                                        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)

                                        List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents());
                                            def found = newList.any {
                                                it.getName().equals(shortenedComponentName)
                                            }
                                            if (found) {
                                                finalComponentList.add(component)
                                                generatedIssuesCounter++
                                            } 
                        }

     }


    createFeature(issue, finalComponentList)

void createFeature(Issue issue, Collection < ProjectComponent > componentList) {
    JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext();


    long issueLinkType = Configuration_SuperFeature.hierarchyIssueLinkType as long
    long sequence = Configuration_SuperFeature.sequence as long
    long myissueID = issue.getId() as long
    // the key of the project under which the version will get created
    final String projectKey = Configuration_SuperFeature.projectKey 
    // the start date - optional
    final Date startDate = null
    // the release date - optional
    final Date releaseDate = null
    // a description for the new version - optional
    final String description = null
    // id of the version to schedule after the given version object - optional
    final Long scheduleAfterVersion = null
    // true if this is a released version
    final boolean released = false
    def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
    assert project: "Could not find project with key $projectKey"
    ProjectComponentManager projectComponentManager = ComponentAccessor.getProjectComponentManager()

    Collection < ProjectComponent > updatedComponentList = issue.getComponents()
    for (ProjectComponent component: componentList) {

        String componentName = component.getName()
        def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1)
        def projectName = componentName.substring(0, componentName.indexOf("-"))

        def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName)
        List < String > newIssueProjectVersionIDs = new ArrayList < String > ()
        newIssueProjectVersionIDs = newIssueproject.getVersions().collect {
            it.getName()
        }

        def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(Configuration_SuperFeature.investmentAreaCustomField); 
        def value = issue.getCustomFieldValue(customField);


         def matchedVersions = issue.getFixVersions().intersect(newIssueproject.getVersions(), Version.NAME_COMPARATOR)





        ProjectComponent newComponent = projectComponentManager.findByComponentName(newIssueproject.getId(), shortenedComponentName)


        def componentArray = new String[1]
        componentArray[0]=newComponent.getName()


        def versionCreator = ComponentAccessor.versionManager.&createVersion.rcurry(startDate, releaseDate, description, newIssueproject.id, scheduleAfterVersion, released)
        def mynewVersions = issue.fixVersions.intersect(newIssueproject.versions, Version.NAME_COMPARATOR).collect {
            versionCreator it.name + '-Inbox'
        }





        //  long newIssueCreatedID = newissue.getId() as long
        // def labelManager = ComponentAccessor.getComponent(LabelManager)
        // labelManager.addLabel(authenticationContext.getLoggedInUser(), newIssueCreatedID, "SF-Child", false)


        // updatedComponentList.removeAll(component)
        // projectComponentManager.updateIssueProjectComponents(issue, updatedComponentList)
         updatedComponentList.removeAll(component)
        // issue.setComponents(updatedComponentList)

                //     issue.update {
                //     setComponents(updatedComponentList)
                // }

                issue.set {
                     setComponents(updatedComponentList)

            }
        Issue newissue = Issues.create(projectName, 'Feature') {
            setSummary("["+shortenedComponentName+"] "+issue.getSummary())
            setDescription("This feature has been generated as child of a super feature. Please use this text area to add child feature specific information.")
            setReporter(authenticationContext.getLoggedInUser())
            setCustomFieldValue(customField.getFieldName(), value)
            setFixVersions(mynewVersions as String[])
            setComponents (componentArray as String[])
            setLabels(["SF-Child"] as String [])
        }

                newissue.link(Configuration_SuperFeature.hierarchyIssueLinkType, issue)

    }
}

1 answer

0 votes
Mohamed Benziane
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 27, 2023

Hi,

Can you provide the error message, the link seems to be broken

Suggest an answer

Log in or Sign up to answer