diff --git a/src/main/scripts/releases/4.1/adhoc/forceSelectFormVersionForReports.js b/src/main/scripts/releases/4.1/adhoc/forceSelectFormVersionForReports.js index b8eabd9a7..a79afa13f 100644 --- a/src/main/scripts/releases/4.1/adhoc/forceSelectFormVersionForReports.js +++ b/src/main/scripts/releases/4.1/adhoc/forceSelectFormVersionForReports.js @@ -1,8 +1,10 @@ +load('../../utils/audit.js'); var programId = "834f6ec8-100b-44c2-9527-72d12d6edd89", projects = [], reports = [], activities = [], - reportName= "Progress Report 1", activities = [], newFormVersion = NumberInt(1), counter = 0; + reportName= "Progress Report 1", activities = [], newFormVersion = NumberInt(1), counter = 0, + user="system"; -db.project.find({programId: programId}).forEach(function(program) { - projects.push(program.projectId); +db.project.find({programId: programId}).forEach(function(project) { + projects.push(project.projectId); }); print("Projects: " + projects.length); db.report.find({projectId: {$in: projects}, name: reportName }).forEach(function(report) { @@ -13,7 +15,9 @@ db.report.find({projectId: {$in: projects}, name: reportName }).forEach(function print("Reports length " + reports.length + " reports list " + reports); db.activity.find({activityId: {$in: activities}, progress: "planned"}).forEach(function(activity) { if (!activity.formVersion) { + activity.formVersion = newFormVersion; db.activity.updateOne({activityId: activity.activityId}, {$set: {formVersion: newFormVersion}}); + audit(activity, activity.activityId, 'au.org.ala.ecodata.Activity', user); print("Activity " + activity.activityId + " updated."); counter++; }