Hello Everyone,
Please i need to create (or modify the current script) a Scripted Fields to calculate the sum of Loads Planned and Consumed according to the users entity and NOT THE ACTIONS ENTITY.
Example :
If the users are from the ORGA entity and they timetrack in Tempo, the Scripted Fields must show me the sum of Loads Planned and Consumed according the users of ORGA entity. (the same for DSI entity)
Please find below the script currently used :
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.math.RoundingMode;
List STATUS_ID = ["10000", "10005", "10011"] // 10000 : Epic, 10005 : Sous-phase, 10011 : Projet
// Check if the issue is an Epic issue
if (issue.fields.issuetype.id in STATUS_ID ) {
// Get the timeestimate custom field to use in the script
def timeEstimateField = "timespent"
// Handle if the timeestimate Field does not exist
if (timeEstimateField == null) {
logger.info("timeEstimate field does not exist ");
return;
}
List<Map> issues;
if(issue.fields.issuetype.id == "10000" && issue.fields.project.key != "PA"){
issues = getAllIssuesByEpic(issue.key, timeEstimateField)
}
else if(issue.fields.issuetype.id == "10005"){
issues = getAllSubtask(issue.key, timeEstimateField)
}
else if(issue.fields.issuetype.id == "10011"){
if(issue.fields.customfield_10038 != null){
if(issue.fields.customfield_10038.value == "Type Maintenance corrective"){
issues = getAllIssuesByProjectMACO(issue.key, issue.fields.customfield_10088, timeEstimateField)
}
else if(issue.fields.customfield_10038.value == "Type Pilotage"){
issues = getAllIssuesPilotage(timeEstimateField)
}
else{
issues = getAllIssuesByProject(issue.key, issue.fields.customfield_10088, timeEstimateField)
}
}
}
else if(issue.fields.issuetype.id == "10000" && issue.fields.project.key == "PA"){
if(issue.fields.customfield_10038 != null){
if(issue.fields.customfield_10038.value == "Type Maintenance corrective"){
issues = getAllIssuesByEpicPAMACO(issue.key, timeEstimateField)
}
else if(issue.fields.customfield_10038.value == "Type Pilotage"){
issues = getAllIssuesPilotage(timeEstimateField)
}
else{
issues = getAllIssuesByEpicPA(issue.key, timeEstimateField)
}
}
}
// Sum the Story Points for all the Story issues returned
def estimate = issues.collect { Map issue ->
issue.fields[timeEstimateField] ?: 0
}.sum()
// return the estimate value if it is not null and return 0 if it has no value
if(estimate){
return Double.parseDouble(getJoursHomme(estimate)) ?: 0;
}
else{
return 0
}
}
List<Map> getAllIssuesByEpic(String issueKey, String timeEstimateField){
// Get all issues below the the Epic Issue
/*def allIssues = get("/rest/agile/1.0/epic/${issue.key}/issue")
.queryString("jql", "parentEpic =${issue.key} and issuetype in ('Sous-phase', Action)") //and 'Entité' = DSI
.queryString("fields", "parent,$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map> */
def allIssues = get("/rest/api/3/search")
.queryString("jql", "issuetype = Action AND linkedissue = "+issueKey+" AND 'Entité[Dropdown]' = DSI") //and 'Entité' = DSI
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return allIssues;
}
List<Map> getAllIssuesByProject(String issueKey, def project, String timeEstimateField){
if(project == null){
// Get all issues below the the Epic Issue
def result = get("/rest/api/3/search")
.queryString("jql", "issuetype = Action AND linkedissue in linkedIssues("+issueKey+",\"Phases\") AND 'Entité[Dropdown]' = DSI")
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return result;
}
else{
def result = get("/rest/api/3/search")
.queryString("jql", "project = "+ project.key +" AND issuetype = Action AND 'Entité[Dropdown]' = DSI")
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return result;
}
}
List<Map> getAllSubtask(String issueKey, String timeEstimateField){
// Get all issues below the the Epic Issue
def allSubtasks = get("/rest/api/3/search")
.queryString("jql", "parent ="+issueKey+" AND issuetype = Action AND 'Entité[Dropdown]' = DSI")
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return allSubtasks;
}
List<Map> getAllIssuesByEpicPA(String issueKey, String timeEstimateField){
// Get all issues below the the Epic Issue
def result = get("/rest/api/3/search")
.queryString("jql", "issuetype = Projet and \"Epic Link\" = "+issueKey)
.asObject(Map)
.body
.issues as List<Map>
List<Map> issues = new ArrayList<Map>();
for(int i = 0; i < result.size(); i++){
List<Map> actions = getAllIssuesByProject(result.get(i).key, result.get(i).fields.customfield_10088, timeEstimateField)
actions.collect { Map issue ->
issues.add(issue)
}
}
return issues;
}
String getJoursHomme(def estimateSeconds){
def estimateHours = ((estimateSeconds/60)/60)
//def days = estimateHours.intValue() / 8
def days = estimateHours / 8
DecimalFormat nf = (DecimalFormat) NumberFormat.getInstance();
nf.setGroupingUsed(false);
nf.setMaximumFractionDigits(2)
nf.setRoundingMode(RoundingMode.UP);
return nf.format(days)
}
List<Map> getAllIssuesPilotage(String timeEstimateField){
// Get all issues of the project Pilotage
def allIssues = get("/rest/api/3/search")
.queryString("jql", "project = PILOT AND 'Entité[Dropdown]' = DSI")
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return allIssues;
}
List<Map> getAllIssuesByEpicPAMACO(String issueKey, String timeEstimateField){
// Get all issues below the the Epic Issue
def result = get("/rest/api/3/search")
.queryString("jql", "issuetype = Projet and \"Epic Link\" = "+issueKey)
.asObject(Map)
.body
.issues as List<Map>
List<Map> issues = new ArrayList<Map>();
for(int i = 0; i < result.size(); i++){
List<Map> actions = getAllIssuesByProjectMACO(result.get(i).key, result.get(i).fields.customfield_10088, timeEstimateField)
actions.collect { Map issue ->
issues.add(issue)
}
}
return issues;
}
List<Map> getAllIssuesByProjectMACO(String issueKey, def project, String timeEstimateField){
if(project != null){
def result = get("/rest/api/3/search")
.queryString("jql", "project = "+ project.key +" AND 'Entité[Dropdown]' = DSI")
.queryString("fields", "$timeEstimateField")
.asObject(Map)
.body
.issues as List<Map>
return result;
}
}
You can download the script in a txt file from here : Scripted Fields.txt
Best Regards,
Thank You.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.