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,364,902
Community Members
 
Community Events
168
Community Groups

Custom script post-function

After Jira Upgrade i am facing the issue with Script post-function 

my Script is 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonSlurper
// import com.atlassian.jira.issue.AttachmentManager
// import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
//import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.label.LabelManager
import org.springframework.util.StringUtils
// import com.atlassian.jira.issue.label.LabelManager
import org.springframework.util.StringUtils
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response

import org.apache.log4j.Logger
import org.apache.log4j.Level

// def log = Logger.getLogger("com.GISD.SUCS.CreateIssue")
log.setLevel(Level.DEBUG)
import groovy.transform.BaseScript
// @BaseScript FieldBehaviours behaviours
@BaseScript CustomEndpointDelegate delegate
 
gisdSUCSFormEndPoint(httpMethod: "POST") { MultivaluedMap queryParams, String body ->
   
   // This section defines the methods used to transform the request into an issue
   def customFieldMgr = ComponentAccessor.customFieldManager
   def issueService = ComponentAccessor.getIssueService()
   def params = issueService.newIssueInputParameters()
   def constantsManager = ComponentAccessor.getConstantsManager()
   def optionsManager = ComponentAccessor.optionsManager
   def projectManager = ComponentAccessor.getProjectManager()
   // def project = projectManager.getProjectObjByKey(forms.project)
   def userManager = ComponentAccessor.getUserManager()
   def attachmentMgr = ComponentAccessor.getAttachmentManager()
   def labelManager = ComponentManager.getComponentInstanceOfType(LabelManager.class)
   
   def forms = new JsonSlurper().parseText(body) as Map<String,String>
   String opco_value = forms.OpCo_1
//   def field = getFieldByName("Labels")

// log.debug "This is the field: ${field}"
// field.addLabel("opco_intake")

def text = """

------------------------------------------------------------------------

*+CONTACT INFORMATION AND URGENCY+*

------------------------------------------------------------------------


Submission Type: ${forms.submission_type}

Developer name(s): ${forms.developer}

Email: ${forms.email}

OpCo: ${forms.OpCo_1}
Sub-OpCo:  ${forms.OpCo_1}

Is this an emergency?: ${forms.emergency}

 

------------------------------------------------------------------------

*+USE CASE METADATA+*

------------------------------------------------------------------------

 
Description: ${forms.description}

Security Domain(s): ${forms.security_domain}

Cyber Kill Chain: ${forms.cyber_kill_chain}

MITRE ATT&CK Framework ID(s): ${forms.mitre_attack}



------------------------------------------------------------------------

*+USE CASE QUERY+*

------------------------------------------------------------------------


Cron Schedule: ${forms.cron_schedule}

Time Period:  ${forms.time_period}

Splunk SPL:  ${forms.splunk_spl}



------------------------------------------------------------------------

*+HISTORICAL SEARCH & PERFORMANCE+*

------------------------------------------------------------------------


Historical Results:  ${forms.historical_results}

Historical Search Date Range:  ${forms.historical_search}

Total Alerts:  ${forms.total_alerts} ${forms.total_alerts_2}

False Positive Count:  ${forms.false_positive_count}

Estimated Time to investigate an Alert (In Hours):  ${forms.Estimated_time_to_investigate}

Job Runtime:  ${forms.job_runtime}

Job Disk Quota:  ${forms.job_disk_quota}



------------------------------------------------------------------------

*+ADDITIONAL INFORMATION+*

------------------------------------------------------------------------


GSIRT Actions:  ${forms.gsirt_actions}
Developer Notes:  ${forms.developer_notes}


"""

   //This section defines variables and their data types

   // Get a user who has permissions to create issues
   // This must be changed to an existing user on your instance
   // This user also defaults to the Reporter
   def user = userManager.getUserByKey("svcacct-confluence")
   def user1 = "svcacct-confluence"
   log.debug "This is the Reporter: ${user1}"
   def summary = "OpCo Use Case Intake Request"   //Could be hard-coded in the form.
   // depricated.  def requestType = "Access"
   // def project = projectService.getProjectByKey(user, "SOCT").getProject();


   // This sets the Project ID based on the Form
   // We can probably hard code these on each created form so that we only need to use one endpoint.
   // Will discuss with Ryon
   params.setProjectId(projectManager.getProjectObjByKey(forms.project).id)
   
   // Defines the Type of Ticket to create. Please note all Jira types doesn't support all issue types, that is you can not create a "Bug" in Jira Core.
   params.setIssueTypeId(constantsManager.allIssueTypeObjects.findByName("Threat Detection").id)
//   params.setReporterId(user.name)
   params.setReporterId(user1)
   params.setSummary(summary + " | " + opco_value)
   
   // This Description section has been customized to aggregate all of the data within the form that
   // does not have a corresponding custom field.  This data has also been formated for easier
   // readablity in the created JIRA Issue.  see https://code-jira-staging.am.sony.com/browse/OPS-44511 for example
   params.setDescription(text)

   // setAssigneeId requires a string instead a variable or keyID
   params.setAssigneeId("davisd")
//   log.debug "This is the field: ${field}"
   // labelManager.addLabel(user, "opco_intake")
   // This section defines the customFields and declares the variables
   // and sets the value of the variables

   // customField Type - Cascading Select List
   // Selecting the parent field and convert to string
   def threatDetectionType = "customfield_19100" // SOCT Request Threat Detection - Task Type customfieldID
   def tdField = threatDetectionType.toString()  // Convert to String

   // the value to set using the optionID of the select list value
   def threatDetectionTypeValP = "22500" // SOCT Request Threat Detection - Task Type Value = Creation
   def tdVal = threatDetectionTypeValP.toString()
   // a single select list custom field name
   def targetSystemType = "customfield_17621" // SOCT Request Threat Detection - Target System customfieldID child field
   def tsField = targetSystemType.toString()
   // the value to set using the optionID of the child select list value
   def requestTypeValC = "20529" // SOCT Request Threat Detection - Target System Value
   def tsVal = requestTypeValC.toString()

   // Add the customfields and values to the parameters used when creating an Issue
   log.debug "SOCT Request Threat Detection - Task Type: ${tdField}"
   log.debug "SOCT Request Threat Detection - Task Value: ${tdVal}"
   log.debug "SOCT Request Threat Detection - Target System: ${tdField}"
   log.debug "SOCT Request Threat Detection - Target System Value: ${tdVal}"
   params.addCustomFieldValue(tdField, tdVal)
   params.addCustomFieldValue(tsField, tsVal)
   // Set the Label on the Issue
//   log.debug "This is the field: ${field}"
  // field.addLabel("opco_intake")  
   /*
   How to manage attachments from forms...

   CreateAttachmentParamsBean attachmentBean =
   new CreateAttachmentParamsBean.Builder(new File(fileName),
   newFileName, "text/plain", user, issue).build();
 */

   log.debug "This is the assignee: ${"GSIRT SOC CA"}"
   
   log.debug "These are the parameters for the created Issue: Reporter: ${user} Project ID: ${forms.project} Summary: ${summary}"

  // Validate issue creation  
   def createValidationResult = issueService.validateCreate(user, params)
   assert  !createValidationResult.errorCollection.hasAnyErrors()
   
   
   def issueManager = ComponentAccessor.issueManager
   def issue = issueService.create(user, createValidationResult).issue
   
   //*********** How do I update the custom field when the issue create has already been validated ?? ************
   // None of these solutions worked
   //def val = issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
   //def upissue = event.issue
   //def customField = customFieldMgr.getCustomFieldObjectByName(fieldName)
   // customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(fieldName), setValue), new DefaultIssueChangeHolder())
   
   log.debug "Created issue : ${issue.key}"
 
   
   
   return Response.ok("Your request has been successfully submitted " + issue).type(MediaType.TEXT_HTML).build()
   
}

12.PNG13.PNG

1 answer

0 votes

Hi @G Ashok 

 

This error message means that the file do not exist on the server or the user running server do not have permissions on this file.

 

What JIRA and Scriptrunner do you upgrade from and to what version ?

Jira Version is 8.22.6 and Scriptrunner version 7.0

the server permissions are good 

Have you try to clear classloader and jira cache using scriptrunner built-in script ?

Maybe you have to use the Script Editor feature now ?

https://www.adaptavist.com/blog/save-and-manage-scriptrunner-scripts-with-the-new-script-editor

Suggest an answer

Log in or Sign up to answer