cannot find matching method

Hi,

My script was ran in 6.x version after upgrading to 7.2.6 then not working. This use to send attachment when issue resolve.

 

Here is the code that I used.

////Values getting from workflow transition screen c. 
           def changeItems = transientVars["changeItems"]
           def uploadChanges = changeItems.findAll { item -> item.getField() == "Attachment" && item.getFieldType() == "jira" }
   
           uploadChanges.each { uploadChange ->
           def Attachment attachment = attachmentManager.getAttachment(uploadChange.getTo()?.toLong())

Getting errors as below

 

  1. groovy.lang.MissingPropertyException: No such property: transientVars for class: com.custom.Script607 at com.custom.Script607.run(Script607.groovy:160)

2. item.getField()   - Cannot find matching method. please check if the declared type is right and if the method exist

3. item.getFieldType() - Cannot find matching method. please check if the declared type is right and if the method exist

4. attachmentManager.getAttachment(uploadChange.getTo()?.toLong())  Same error as 2,3

 

Can anyone suggest me what is the change in new JIRA version 7.2 ? How I can fix this?

1 answer

0 vote

The first issue causes the others. Is this a workflow function? transientVars should work fine. Can you add a screenshot of the function config.

@Jamie Echlin (Adaptavist) Here is the screenshot of the workflow post function

 

wk-flowpostfunction.JPG

 

Script is

 

package com.custom
import com.atlassian.jira.event.issue.AbstractIssueEventListener
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.AttachmentManager;
import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import org.apache.log4j.Category
import java.sql.Timestamp
import com.atlassian.jira.util.AttachmentUtils;
import com.atlassian.jira.util.PathUtils
import javax.mail.Multipart
import javax.mail.internet.MimeMultipart
import javax.mail.BodyPart
import javax.mail.internet.MimeBodyPart
import javax.activation.FileDataSource
import javax.activation.DataHandler
 
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
AttachmentManager attachmentManager = componentManager.getAttachmentManager()
pathManager = componentManager.getAttachmentPathManager()
 
// Get the related Application
def cfRelAppID     = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Related Application ID")
def cfRelAppIDVal  = "" + issue.getCustomFieldValue(cfRelAppID)?.value
def cfrelAppSupportEmailVal
if (cfRelAppIDVal != null ){
 MutableIssue relAppObj = componentManager.getIssueManager().getIssueObject(cfRelAppIDVal)
 def cfrelAppSupportEmail = customFieldManager.getCustomFieldObjectByName("Support Email")
 cfrelAppSupportEmailVal = relAppObj.getCustomFieldValue(cfrelAppSupportEmail)?.value
 // log.debug ("App email is ${cfrelAppSupportEmailVal}")
 def cfrelAppSupportEmailSig    = customFieldManager.getCustomFieldObjectByName("Support Email Signature")
 cfrelAppSupportEmailSigVal = relAppObj.getCustomFieldValue(cfrelAppSupportEmailSig)?.value
}

if (mailServer) {
    //TO: Email Address//
 ///////TO: Email Address////////
 def cfcust = customFieldManager.getCustomFieldObjectByName("Customer Email")
 def cfcustVal =  "" + issue.getCustomFieldValue(cfcust)?.value
     
 Email email = new Email(cfcustVal)
    
    ///////FROM: Email Address////////
    if (cfrelAppSupportEmailVal != null ){
    email.setFrom("" + cfrelAppSupportEmailVal)
    }
    
    ///////CC: Email Address////////
 CCEmailID = customFieldManager.getCustomFieldObjectByName("CC Address Emails")
 def CCEmailAddr = issue.getCustomFieldValue(CCEmailID)
    if (CCEmailAddr != null ){
    email.setCc("" + CCEmailAddr)
    }
    
    ///////Email Subject////////
    email.setSubject("($issue.key) - $issue.summary")
  //  email.setSubject("Hello Testing Attachment");
  
    ///////Set the Email Mime Type/////  
    email.setMimeType("text/Plain");
    
    ///////Email Body////////   
 String content
    
    if ( issue.status.name == "Waiting For Triage"){
     content = "TECH Help Desk Ticket $issue.key has been created"
    }else if( issue.status.name == "Waiting on Customer"){
     content = "TECH Help Desk Ticket $issue.key Needs More Information." 
    }else if( issue.status.name == "Resolved"){
     content = "TECH Help Desk Ticket $issue.key has been resolved." 
    }
     
         content = content +
       "\n\nShort Description: $issue.summary\n\n" +
     "\nCustomer:              ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Customer"))?.value}" + 
     "\nRelated Provider:      ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Related Provider"))?.value}" + 
     "\nRelated Application:   ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Related Application"))?.value}" + 
     "\nService Request Type:  ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Service Request Type"))?.value}" + 
     "\nRequest Source Type:   ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Request Source Type"))?.value}"  +
         "\nRequest Received Time: ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Request Received Time")).format('MM/dd/yyyy hh:mm a')}" +
     "\nCreated:               ${issue.getCreated().format('MM/dd/yyyy hh:mm a')}"  
         
    if( issue.status.name == "Waiting For Triage"){
    content = content +
              "\n\nDescription:\n\n$issue.description"
    }else if( issue.status.name == "Waiting on Customer"){
          
           ////Checking for attachment.
        Multipart multipart = new MimeMultipart("mixed");
        
    
        ////Values getting from workflow transition screen c. 
           def changeItems = transientVars["changeItems"]
           def uploadChanges = changeItems.findAll { item -> item.getField() == "Attachment" && item.getFieldType() == "jira" }
   
           uploadChanges.each { uploadChange ->
           def Attachment attachment = attachmentManager.getAttachment(uploadChange.getTo()?.toLong())
            
              if (attachment) {
                  addAttachmentsToMessage(multipart,attachment);
                        
       }
                
           }
          email.setMultipart(multipart);
       
           content = content +
                    "\n\nPlease provide more information:\n\n${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Customer Comment"))?.value}"
           
         
  }else if( issue.status.name == "Resolved"){

         ////Checking for attachment.
        Multipart multipart = new MimeMultipart("mixed");
        
    
        ////Values getting from workflow transition screen for attachment field.
           def changeItems = transientVars["changeItems"]
           def uploadChanges = changeItems.findAll { item -> item.getField() == "Attachment" && item.getFieldType() == "jira" }
   
           uploadChanges.each { uploadChange ->
           def Attachment attachment = attachmentManager.getAttachment(uploadChange.getTo()?.toLong())
            
              if (attachment) {
                 addAttachmentsToMessage(multipart,attachment);
                        
       }
                
           }
          email.setMultipart(multipart);

    content = content +
    "\nResolved:              ${issue.resolutionDate.format('MM/dd/yyyy hh:mm a')}" +
    "\nResolution:            $issue.resolution.name" +
    "\n\nResolved Comment - :    ${issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Customer Comment"))?.value}"
  }
     
        if (cfrelAppSupportEmailSigVal != null ){
         content = content + "\n\n" + cfrelAppSupportEmailSigVal
        }   
        
       //email.setBody(attachFileName + "total added attachments" + NumOfAttachedfiles);
        email.setBody(content)
        
      ///////SEND Email ////////
       SingleMailQueueItem item = new SingleMailQueueItem(email);
       ComponentAccessor.getMailQueue().addItem(item);
     
  }else {
   log.error "No SMTP mail server defined"
}
private void addAttachmentsToMessage(Multipart multipart, Attachment attachment){
                BodyPart attachBody = new MimeBodyPart();
                def attachedFile = AttachmentUtils.getAttachmentFile(attachment);
                FileDataSource source = new FileDataSource(attachedFile);
                attachBody.setDataHandler(new DataHandler(source));
               attachBody.setFileName(attachment.filename);
                multipart.addBodyPart(attachBody);
}

 

 

 I got the error at this point.

           
def changeItems = transientVars["changeItems"]           def uploadChanges = changeItems.findAll { item -> item.getField() == "Attachment" && item.getFieldType() == "jira" }              uploadChanges.each { uploadChange ->           def Attachment attachment = attachmentManager.getAttachment(uploadChange.getTo()?.toLong())

 

 

You can't use eg componentManager.getCustomFieldManager in JIRA 7.

See https://scriptrunner.adaptavist.com/latest/jira/releases/UpgradingToJira7.html#_removal_of_componentmanager_methods

When you've fixed those probably everything else will work.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Apr 17, 2018 in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

798 views 2 19
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you