We upgraded JIRA and script runner and this code stopped working.
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import static com.atlassian.jira.issue.IssueFieldConstants.*
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import org.apache.log4j.Category
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.fields.FieldManager
import com.atlassian.jira.util.ImportUtils
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
// On copie la ‘issue’ en cours vers une variable que l’on va manipuler
MutableIssue myIssue = issue
// Définition d’objet permettant l’accès à certaines données de Jira
def fieldManager=ComponentAccessor.getFieldManager();
def watcherManager = ComponentAccessor.getWatcherManager();
def userManager = ComponentAccessor.getUserManager();
def groupManager = ComponentAccessor.getGroupManager();
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
IssueManager issueManager = ComponentAccessor.getIssueManager();
// Définition des champs de Jira
CustomField attrib_ = customFieldManager.getCustomFieldObject("customfield_10813") //Nfeed Attribué
CustomField serv_ = customFieldManager.getCustomFieldObject("customfield_10812")
CustomField appli_ = customFieldManager.getCustomFieldObject("customfield_10808")
CustomField proces_ = customFieldManager.getCustomFieldObject("customfield_10811")
CustomField bloc_ = customFieldManager.getCustomFieldObject("customfield_10809")
CustomField attrib = customFieldManager.getCustomFieldObject("customfield_10901") //Bal générique
CustomField serv = customFieldManager.getCustomFieldObject("customfield_10900")
CustomField servF = customFieldManager.getCustomFieldObject("customfield_11301")
CustomField appli = customFieldManager.getCustomFieldObject("customfield_10804")
CustomField proces = customFieldManager.getCustomFieldObject("customfield_10803")
CustomField bloc = customFieldManager.getCustomFieldObject("customfield_10805")
CustomField destinataire = customFieldManager.getCustomFieldObject("customfield_11400")
CustomField dest = customFieldManager.getCustomFieldObject("customfield_11805")
def changeHolder = new DefaultIssueChangeHolder();
def valTypeName = myIssue.getIssueTypeObject().getName()
def valTypeInt = myIssue.getIssueTypeObject().getId() as Integer
def isCDSselected = valTypeInt==10100 || valTypeInt==10101
def mailBALSend=myIssue.getCustomFieldValue(attrib) as String;
def changed=false
if (isCDSselected) { //Traitement unique pour une demande CDS
def assignee = myIssue.assigneeId;
if (myIssue.assigneeId==null){
def usera = userManager.getUserObject("CDS-PILOTAGE");
myIssue.setAssignee(usera);
watcherManager.startWatching(usera , myIssue.genericValue);
def assigneeCDS = myIssue.assigneeId;
def assigneeWatcherCDS = userManager.getUserObject(assigneeCDS );
watcherManager.startWatching(assigneeWatcherCDS , myIssue.genericValue);
myIssue.store()
} else {
if (myIssue.assigneeId=="cds-cap" || myIssue.assigneeId=="c2s-aubay"|| myIssue.assigneeId=="cds-ob") {
def assignCDS = myIssue.assigneeId;
def assigneeWatchCDS = userManager.getUserObject(assignCDS );
if (assigneeWatchCDS==null){
if (myIssue.assigneeId=="cds-ob"){
assigneeWatchCDS = userManager.getUserObject("c2s-aubay");
}
if (myIssue.assigneeId=="cds-cap"){
assigneeWatchCDS = userManager.getUserObject("CDS-CAP");
}
if (myIssue.assigneeId=="c2s-aubay"){
assigneeWatchCDS = userManager.getUserObject("C2S-AUBAY");
}
}
watcherManager.startWatching(assigneeWatchCDS , myIssue.genericValue);
}
}
}
else { // Pour tous les autres types de demande
if (myIssue.getCustomFieldValue(bloc_)!=null){ // On vérifie si Nov a été utilisé (Insertion externe)
if (myIssue.getCustomFieldValue(destinataire)!=null){
if (event.getEventTypeId()==1 || myIssue.getCustomFieldValue(dest) != myIssue.getCustomFieldValue(destinataire).first()){ //Création ou Modification de dest
attrib.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(attrib),myIssue.getCustomFieldValue(attrib_).first()),changeHolder);
mailBALSend=myIssue.getCustomFieldValue(attrib_).first();
changed=true
}
dest.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(dest),myIssue.getCustomFieldValue(destinataire).first()),changeHolder);
} else {
if (event.getEventTypeId()==1){ //Création ou Modification de dest
attrib.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(attrib),myIssue.getCustomFieldValue(attrib_).first()),changeHolder);
}
}
serv.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(serv),myIssue.getCustomFieldValue(serv_).first() ),changeHolder);
appli.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(appli),myIssue.getCustomFieldValue(appli_).first() ),changeHolder);
proces.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(proces),myIssue.getCustomFieldValue(proces_).first() ),changeHolder);
bloc.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(bloc),myIssue.getCustomFieldValue(bloc_).first() ),changeHolder);
if (myIssue.getCustomFieldValue(attrib)!=null && !changed){
mailBALSend=myIssue.getCustomFieldValue(attrib);
}
def Service=myIssue.getCustomFieldValue(serv_).first() as String
def listServGroup = groupManager.getAllGroups().findAll {it.name.contains(Service)}
def firstGroup = listServGroup.first()
servF.updateValue(null, issue, new ModifiedValue(myIssue.getCustomFieldValue(servF),listServGroup ),changeHolder);
def nuser = userManager.getUserObject(myIssue.getCustomFieldValue(attrib_).first().replaceAll(' ',''));
if (nuser != null) {
watcherManager.startWatching(nuser , myIssue.genericValue);
}
myIssue.store()
}
else {
def Service=myIssue.getCustomFieldValue(serv) as String
def listServGroup = groupManager.getAllGroups().findAll {it.name.contains(Service)}
def firstGroup = listServGroup.first()
servF.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(servF),listServGroup ),changeHolder);
def t1=(myIssue.getAssignee()!=null)
if (!t1) { // On vérifie si la demande n'a pas déjà été attribuée manuellement.
if (myIssue.getCustomFieldValue(attrib)!=null){
mailBALSend=myIssue.getCustomFieldValue(attrib).replaceAll(' ','');
}
def nuser = userManager.getUserObject(myIssue.getCustomFieldValue(attrib).replaceAll(' ',''));
myIssue.setAssignee(nuser);
def assignee = myIssue.assigneeId;
def assigneeWatcher = userManager.getUserObject(assignee);
watcherManager.startWatching(assigneeWatcher , myIssue.genericValue);
myIssue.store()
boolean wasIndexing = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
ComponentAccessor.getIssueIndexManager().reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing)
myIssue.store()
}
}
}
CustomField crebrou = customFieldManager.getCustomFieldObject("customfield_10735") // Créer Brouillon
def t0=!(mailBALSend==null)
if (t0) {
def isAMail0=mailBALSend.reverse().take(7).reverse()=="@lbl.fr"
if (isAMail0) {
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
SMTPMailServer mailServer = mailServerManager.getDefaultSMTPMailServer()
if (mailServer) {
Email email0 = new Email(mailBALSend) // Set the TO address, optionally CC and BCC
email0.setSubject("JIRA PRODUCTION: La demande '${myIssue.summary}' a évolué (ne pas répondre)") // todo: check the subject value
String content0 = "Bonjour,\n\nLa demande '${myIssue.summary}' de type "+myIssue.getIssueTypeObject().getName()+" a évolué au statut : "+myIssue.getStatusObject().getName()+".\nVeuillez vous connecter à Jira pour plus de précision:\nhttps://jira-itp.prod.adsi.lcl.fr/browse/${myIssue.getKey()}\n---------------------------------------------------------------------\nCe message a été généré automatiquement, il est inutile d'y répondre."; //email's body.
email0.setBody(content0)
mailServer.send(email0)
}
else {
log.error "No SMTP mail server defined"
}
}
}
Thanks ind advice for all help and ints
Hi,
All the errors that say "Cannot find method for com.atlassian.jira.issue.watchers.WatcherManager...) you should try replacing myIssue.getGenericValue() by myIssue
The errors that talk about "java.lang.Object", as I told in my last comment, can be a "false positive" because you declared the variable with def instead of the concrete types. It's not an error, but when the code is not in execution time, it detects as error all these variables.
The one that talks about the IssueIndexManager and the MailServerManager you should try replacing this:
(line 149)
ComponentAccessor.getIssueIndexManager().reIndex(issue)
with this:
ComponentAccessor.issueIndexManager.reIndex(issue)
and this:
(line 165)
ComponentManager componentManager = ComponentManager.getInstance()
MailServerManager mailServerManager = componentManager.getMailServerManager()
with this:
MailServerManager mailServerManager = componentAccessor.mailServerManager
Try executing the code with this changes and tell me if it runs successfully.
Remember that there could be some errors in editor that you can ignore because it will be solved in execution time (java.lang.Object and issue errors)
Regards,
Marcos
Hi Marcos ,
thank you very much for your precious help.
I will try to solve the problems and I will come back to you.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Are you getting any error?
If you are, could you please send the error too?
Regards,
Marcos.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marcos ,
Thank you for your answer.
yes I have a lot of errors
Thank you in advance for your answer
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
First of all, the error "variable issue is undeclared" is not really an error except if you are running the script on the script console.
It's because in execution time the variable "issue" will be the issue which you are working on. But before compiling, it just a not declared variable.
Most of the errors I see are marked on myIssue calls.
I'm not 100% sure but you should try it replacing myIssue and myIssue.genericValue for issue
Moreover, most of errors could be marked as "Can't find matching java.lang.Object.............." and it could maybe not be an error.
It's because you declare variables with a "def" instead of, for example, "CustomField".
For the other errors, it would be appreciate if you could send the traces of the errors and not just the red mark over it (with mouse hover it shows you a little trace of the error, like you did on first screenshot)
Thank you.
Regards,
Marcos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Marcos ,
thank you very much for your help
here is screenshots with errors
Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.