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

Scriptrunner built-in scrip postfunction to create dynamically subtasks and links isn't working

Gilles Samen December 2, 2019

Hi Community, I'm using the script below in order to create subtasks and link them to the parent issue on scriptrunner. I'm not great at it but the used code is green everywhere so no errors onto it.

 I place the postfunction above after the creat issue initially and abvove the resync database postfunction of native jira.

 The script is always falling and I don't understand why yet. Could you please help me, I'm so helpless.

 Thanks

 

Code (Postfunction):

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfigImpl
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.issue.MutableIssue
import groovy.transform.BaseScript
import org.apache.log4j.Logger
import org.apache.log4j.Level
def customFieldManager = ComponentAccessor.customFieldManager

log.debug(issue)

//Prise en compte du champ Applications SOX
def Apps = customFieldManager.getCustomFieldObjectByName("Applications SOX")
def App = issue.getCustomFieldValue(Apps) as Collection
def Appsize = App.size()

//Prise en compte des services des différentes App
def qv = customFieldManager.getCustomFieldObjectByName ("Service QV")
def QV = issue.getCustomFieldValue(qv) as String
def tbo = customFieldManager.getCustomFieldObjectByName ("Service T4BO")
def TBO = issue.getCustomFieldValue(tbo) as String
def sebdd = customFieldManager.getCustomFieldObjectByName("Service SE_BDD")
def Infra = issue.getCustomFieldValue(sebdd) as String
def crm = customFieldManager.getCustomFieldObjectByName("Service SAP CRM")
def CRM = issue.getCustomFieldValue(crm) as String
def erp = customFieldManager.getCustomFieldObjectByName("SAP ERP Service")
def ERP = issue.getCustomFieldValue(erp) as String
def ship = customFieldManager.getCustomFieldObjectByName("Service Ship")
def Ship = issue.getCustomFieldValue(ship) as String

//Définition de tous les rôles selon les applications
//Qlikview
def rolqv0 = customFieldManager.getCustomFieldObjectByName("Role QV CHURN")
def RolQV0 = issue.getCustomFieldValue(rolqv0) as String
def rolqv1 = customFieldManager.getCustomFieldObjectByName("Role QV Bil_Fac_GC")
def RolQV1 = issue.getCustomFieldValue(rolqv1) as String
def rolqv2 = customFieldManager.getCustomFieldObjectByName("Role QV Facturation")
def RolQV2 = issue.getCustomFieldValue(rolqv2) as String
def rolqv3 = customFieldManager.getCustomFieldObjectByName("Role QV BAG")
def RolQV3 = issue.getCustomFieldValue(rolqv3) as String
def rolqv4 = customFieldManager.getCustomFieldObjectByName("Role QV Encaissements")
def RolQV4 = issue.getCustomFieldValue(rolqv4) as String
def rolqv5 = customFieldManager.getCustomFieldObjectByName("Role QV Impayés_Histo")
def RolQV5 = issue.getCustomFieldValue(rolqv5) as String
def rolqv6 = customFieldManager.getCustomFieldObjectByName("Role QV Prelev Rejets")
def RolQV6 = issue.getCustomFieldValue(rolqv6) as String
def rolqv7 = customFieldManager.getCustomFieldObjectByName("Role QV Relances")
def RolQV7 = issue.getCustomFieldValue(rolqv7) as String
def rolqv8 = customFieldManager.getCustomFieldObjectByName("Role QV Grds Cptes")
def RolQV8 = issue.getCustomFieldValue(rolqv8) as String
def rolqv9 = customFieldManager.getCustomFieldObjectByName("Role QV Périmètre")
def RolQV9 = issue.getCustomFieldValue(rolqv9) as String
def rolqv10 = customFieldManager.getCustomFieldObjectByName("Role QV CRM")
def RolQV10 = issue.getCustomFieldValue(rolqv10) as String
def rolqv11 = customFieldManager.getCustomFieldObjectByName("Role QV Croisement_Solde")
def RolQV11 = issue.getCustomFieldValue(rolqv11) as String
def rolqv12 = customFieldManager.getCustomFieldObjectByName("Role QV FTF")
def RolQV12 = issue.getCustomFieldValue(rolqv12) as String
def rolqv13 = customFieldManager.getCustomFieldObjectByName("Role QV Score_Souscrip")
def RolQV13 = issue.getCustomFieldValue(rolqv13) as String
def rolqv14 = customFieldManager.getCustomFieldObjectByName("Role QV Vente")
def RolQV14 = issue.getCustomFieldValue(rolqv14) as String
def ROLEQV = [RolQV0, RolQV1, RolQV2, RolQV3, RolQV4, RolQV5, RolQV6, RolQV7, RolQV8, RolQV9, RolQV10, RolQV11, RolQV12, RolQV13, RolQV14]
def RoleQV = ROLEQV.size()

//SHIP
def rolship0 = customFieldManager.getCustomFieldObjectByName("Role SHIP - GDP")
def RolShip0 = issue.getCustomFieldValue(rolship0) as String
def rolship1 = customFieldManager.getCustomFieldObjectByName("Role SHIP - Front Office")
def RolShip1 = issue.getCustomFieldValue(rolship1) as String
def rolship2 = customFieldManager.getCustomFieldObjectByName("Role SHIP - Front Office")
def RolShip2 = issue.getCustomFieldValue(rolship2) as String
def ROLESHIP = [RolShip0, RolShip1, RolShip2]
def RoleShip = ROLESHIP.size()

//SE_BDD
def rolbdd0 = customFieldManager.getCustomFieldObjectByName("Role SE_BDD SupAppN1")
def RolBDD0 = issue.getCustomFieldValue(rolbdd0) as String
def rolbdd1 = customFieldManager.getCustomFieldObjectByName("Role SE_BDD SupAppN2")
def RolBDD1 = issue.getCustomFieldValue(rolbdd1) as String
def rolbdd2 = customFieldManager.getCustomFieldObjectByName("Role SE_BDD SupBur")
def RolBDD2 = issue.getCustomFieldValue(rolbdd2) as String
def rolbdd3 = customFieldManager.getCustomFieldObjectByName("Role SE_BDD SupExploitN2")
def RolBDD3 = issue.getCustomFieldValue(rolbdd3) as String
def rolbdd4 = customFieldManager.getCustomFieldObjectByName("Role SE_BDD SupIngéN3")
def RolBDD4 = issue.getCustomFieldValue(rolbdd4) as String
def ROLEBDD = [RolBDD0, RolBDD1, RolBDD2, RolBDD3, RolBDD4]
def RoleBDD = ROLEBDD.size()

//T4BO
def roltbo0 = customFieldManager.getCustomFieldObjectByName("Role T4BO - Back Office")
def RolTBO0 = issue.getCustomFieldValue(roltbo0) as String
def roltbo1 = customFieldManager.getCustomFieldObjectByName("Role T4BO - Front Office")
def RolTBO1 = issue.getCustomFieldValue(roltbo1) as String
def roltbo2 = customFieldManager.getCustomFieldObjectByName("Role T4BO - GDP")
def RolTBO2 = issue.getCustomFieldValue(roltbo2) as String
def ROLETBO = [RolTBO0, RolTBO1, RolTBO2]
def RoleTBO = ROLETBO.size()

//SAP CRM
def crm0 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM")
def CRM0 = issue.getCustomFieldValue(crm0) as String
def crm1 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM Rec")
def CRM1 = issue.getCustomFieldValue(crm1) as String
def crm2 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM Ventes SC")
def CRM2 = issue.getCustomFieldValue(crm2) as String
def crm3 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM BtB")
def CRM3 = issue.getCustomFieldValue(crm3) as String
def crm4 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM Analyse_Conso")
def CRM4 = issue.getCustomFieldValue(crm4) as String
def crm5 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM QPF")
def CRM5 = issue.getCustomFieldValue(crm5) as String
def crm6 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM Exp Part")
def CRM6 = issue.getCustomFieldValue(crm6) as String
def crm7 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM Fin")
def CRM7 = issue.getCustomFieldValue(crm7) as String
def crm8 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM BO")
def CRM8 = issue.getCustomFieldValue(crm8) as String
def crm9 = customFieldManager.getCustomFieldObjectByName("Role SAP CRM OP SI")
def CRM9 = issue.getCustomFieldValue(crm9) as String
def ROLECRM = [CRM0, CRM1 ,CRM2 ,CRM3 ,CRM4 ,CRM5 ,CRM6 ,CRM7 ,CRM8 ,CRM9]
def RoleCRM = ROLECRM.size()

//SAP ERP
def erp0 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Activation")
def ERP0 = issue.getCustomFieldValue(erp0) as String
def erp1 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Back Office")
def ERP1 = issue.getCustomFieldValue(erp1) as String
def erp2 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - BtB")
def ERP2 = issue.getCustomFieldValue(erp2) as String
def erp3 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - BtC")
def ERP3 = issue.getCustomFieldValue(erp3) as String
def erp4 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Conso Analyse")
def ERP4 = issue.getCustomFieldValue(erp4) as String
def erp5 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Expertise Partenaires")
def ERP5 = issue.getCustomFieldValue(erp5) as String
def erp6 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Facturation")
def ERP6 = issue.getCustomFieldValue(erp6) as String
def erp7 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Finance")
def ERP7 = issue.getCustomFieldValue(erp7) as String
def erp8 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Opérations SI")
def ERP8 = issue.getCustomFieldValue(erp8) as String
def erp9 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Other")
def ERP9 = issue.getCustomFieldValue(erp9) as String
def erp10 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - QPF")
def ERP10 = issue.getCustomFieldValue(erp10) as String
def erp11 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Recouvrement")
def ERP11 = issue.getCustomFieldValue(erp11) as String
def erp12 = customFieldManager.getCustomFieldObjectByName("SAP ERP Profile - Vente & SC")
def ERP12 = issue.getCustomFieldValue(erp12) as String
def erp13 = customFieldManager.getCustomFieldObjectByName("SAP ERP Service")
def ERP13 = issue.getCustomFieldValue(erp13) as String
def ROLERP = [ERP0, ERP1, ERP2, ERP3, ERP4, ERP5, ERP6, ERP7, ERP8, ERP9, ERP10, ERP11, ERP12, ERP13]
def RoleERP = ROLERP.size()

//Initialisation
def constantManager = ComponentAccessor.getConstantsManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issueFactory = ComponentAccessor.getIssueFactory()
def subTaskManager = ComponentAccessor.getSubTaskManager()
def issueManager = ComponentAccessor.getIssueManager()

int i,j,k,l,m,n,p;

for (i=0 ; Appsize-1; i++){
for (j=0 ; RoleQV-1; j++){
if ((App[i] == "QlikView")&&(ROLEQV[j] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + QV + "Rôle:" +ROLEQV[j])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
for (k=0; RoleShip-1;k++){
if((App[i] == "SHIP")&&(ROLESHIP[k] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + Ship + "Rôle:" +ROLESHIP[k])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
for (l=0; RoleBDD-1;l++){
if((App[i] == "Systèmes d'exploitation / Base de Données")&&(ROLEBDD[l] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + Infra + "Rôle:" +ROLEBDD[l])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
for(m=0;RoleTBO-1;m++){
if((App[i] == "T4BO")&&(ROLETBO[m] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + TBO + "Rôle:" +ROLETBO[m])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
for(n=0;RoleCRM-1;n++){
if((App[i] == "SAP CRM")&&(ROLECRM[n] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + CRM + "Rôle:" +ROLECRM[n])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
for(p=0;RoleERP-1;p++){
if((App[i] == "SAP ERP")&&(ROLERP[p] != " ")){

MutableIssue newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Création de compte"+ App[i] + "Service :" + ERP + "Rôle:" +ROLERP[p])
newSubTask.setParentObject(issue)
newSubTask.setProjectObject(issue.getProjectObject())
newSubTask.setIssueTypeId(constantManager.getAllIssueTypeObjects().find{it.getName() == "Sub-task"}.id)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, user)
}
}
}

 

Error :

Capture.PNG

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ilya Turov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 3, 2019

judging from the error, which is in 109th row of your script, which seems to be 

def CRM0 = issue.getCustomFieldValue(crm0) as String

I would say that there's no such custom field as "Role SAP CRM"

TAGS
AUG Leaders

Atlassian Community Events