UPDATECHECK Component¶
Function updateOnCustomisation¶
-
updateOnCustomisation
(pkey, dataid)¶ The function checks the updates on customisation
- Arguments
pkey (Object) – the list of key properties and their values
dataid (type) – id of Beneficiary data
- Returns
keyinputs – the list of key parameters
Warning
Update the function names
List of parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | function updateOnCustomisation(dataid, pkey) {
if (pkey != null) { key = pkey };
/*paramater {Object} - get the sheet "PARAMATERS" */
var paramater = ss.getSheetByName("PARAMATERS");
/*control {Object} - get the sheet "CONTROL" */
var control = ss.getSheetByName("CONTROL");
/*data {array} - get the sheet "CONTROL" */
/*["STATUS", "PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year", "formid", "_id", "CONTACT_INFORMATION/Country", "CONTACT_INFORMATION/SubOperation", "CONTACT_INFORMATION/D_Station", "CONTACT_INFORMATIO...]
*/
var data = getData("CONTROL");
/*c1 {number} - index of STATUS column in data[Control Sheet] */
var c1 = data[0].indexOf("STATUS") + 2;
/*c2 {number} - new field: index of User Access column in data [Control Sheet] */
var c2 = data[0].indexOf("USER_ACCESS") + 2;
/*c3 {number} - index of TEMPLATE_PDF column in data [Control Sheet] */
var c3 = data[0].indexOf("TEMPLATE_PDF") + 2;
/*c4 {number} - index of CSV_FILE_SURVEYS in data [Control Sheet] */
var c4 = data[0].indexOf("CSV_FILE_SURVEYS") + 2;
/*c5 {number} - index of CSV_FILE_COUNTRY in data [Control Sheet] */
var c5 = data[0].indexOf("CSV_FILE_COUNTRY") + 2;
/*c55 {number} - index of CSV_FILE_LOCATIONS in data [Control Sheet] */
var c55 = data[0].indexOf("CSV_FILE_LOCATIONS") + 2;
/*c6 {number} - index of Country_node in data [Control Sheet] */
var c6 = data[0].indexOf("Country_Note") + 2;
/*c7 {number} - index of AnalysisData in data [Control Sheet] */
var c7 = data[0].indexOf("AnalysisData") + 2;
/*c8 {number} - index of PartnerData in data [Control Sheet] */
var c8 = data[0].indexOf("PartnerData") + 2;
var CUSTOMISE;
var TEMPLATE;
var COUNTRYNOTE;
var CSV1;
var CSV2;
var TEMPR;
var TEMPLATESUMMARYTABLE;
var TEMPLATESUMMARYTABLEyear = 0;
|
Updates on Control sheet
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | { /*Updates on Control Sheet*/
var meta = getData("META");
var bsurvey = getData("BSURVEY");
for (i = 2; i < data.length; i++) {
if (data[i][2] == "") { continue; }
CUSTOMISE = 0;
TEMPLATE = 0;
COUNTRYNOTE = 0;
CSV1 = 0;
CSV2 = 0;
TEMPR = 0;
TEMPLATESUMMARYTABLE = 0;
if (dataid != null) { if (data[i][data[0].indexOf("_id")] != dataid) { continue; } }
var id = data[i][data[0].indexOf("_id")];
var year = data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")];
var s = 0;
{ /*Status Check*/
/* IS NEW SUBMISSION*/
if (s == 0 && key["TEMP" + id] == null) {
keyinputs["TEMP" + id] = "New"; key["TEMP" + id] = "New";
data[i][data[0].indexOf("STATUS")] = "New";
keyinputs["CUSTOMISE" + id] = ""; key["CUSTOMISE" + id] = "";
keyinputs["TEMPLATE" + id] = ""; key["TEMPLATE" + id] = "";
if (year != 2017) { CUSTOMISE = 1 };
TEMPLATE = 1;
keyinputs["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
key["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
TEMPLATESUMMARYTABLE++; s = 1;
}
/*USERNAME change*/
if (year != 2017 && s == 0 && key['UN' + id] != null && key['UNO' + id] != null && key['UN' + id] != key['UNO' + id] && yearcheck(year) == 1) {
keyinputs["TEMP" + id] = "Changing"; key["TEMP" + id] = "Changing";
data[i][data[0].indexOf("STATUS")] = "Changing";
keyinputs["CSVURL" + id] = ""; key["CSVURL" + id] = ""; CSV1 = 1;
keyinputs["CSVURL2" + id] = ""; key["CSVURL2" + id] = ""; CSV2 = 1;
keyinputs["CUSTOMISE" + id] = ""; key["CUSTOMISE" + id] = "";
CUSTOMISE = 1;
s = 1;
}
/*template update*/
if (dataid == null && s == 0 && key["UUIDBEFORE" + id] != data[i][data[0].indexOf("_uuid")] && key["TEMP" + id] != "CSV File Missing") {
keyinputs["TEMP" + id] = "Updating"; key["TEMP" + id] = "Updating";
data[i][data[0].indexOf("STATUS")] = "Updating";
keyinputs["CUSTOMISE" + id] = ""; key["CUSTOMISE" + id] = "";
keyinputs["TEMPLATE" + id] = ""; key["TEMPLATE" + id] = "";
if (year != 2017) { CUSTOMISE = 1 }; TEMPLATE = 1;
keyinputs["CSVURL" + id] = ""; key["CSVURL" + id] = ""; CSV1 = 1;
keyinputs["CSVURL2" + id] = ""; key["CSVURL2" + id] = ""; CSV2 = 1;
keyinputs["TEMPR" + id] = ""; key["TEMPR" + id] = ""; TEMPR = 1;
keyinputs["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
key["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
TEMPLATESUMMARYTABLE++;
s = 1;
}
/*Pending task*/
if (s == 0) {
if (year != 2017 && key["CUSTOMISE" + id] == "") {
keyinputs["TEMP" + id] = "Pending Tasks"; key["TEMP" + id] = "Pending Tasks";
CUSTOMISE = 1;
data[i][data[0].indexOf("STATUS")] = "Pending Tasks";
s = 1;
}
if (key["TEMPLATE" + id] == "") {
keyinputs["TEMP" + id] = "Pending Tasks"; key["TEMP" + id] = "Pending Tasks";
TEMPLATE = 1;
data[i][data[0].indexOf("STATUS")] = "Pending Tasks";
s = 1;
}
if (key["COUNTRYNOTE" + id] == "UPDATE") {
keyinputs["TEMP" + id] = "Pending Tasks"; key["TEMP" + id] = "Pending Tasks";
COUNTRYNOTE = 1;
data[i][data[0].indexOf("STATUS")] = "Pending Tasks";
s = 1;
}
}
/* NOT FOUND IN KOBO IN CASE CSV FILES ARE DELETED ETC*/
if (dataid == null && yearcheck(year) == 1) {
var l = 0;
var ll = 0;
for (b = 0; b < bsurvey.length; b++) {
if (year == bsurvey[b][bsurvey[0].indexOf("YEAR")]) {
ll++;
for (m = 0; m < meta.length; m++) {
if (bsurvey[b][bsurvey[0].indexOf("formid")] == meta[m][meta[0].indexOf("xform")]) {
if (data[i][data[0].indexOf("Username")] + ".csv" == meta[m][meta[0].indexOf("data_value")]) {
l++;
}
}
}
}
}
if (l < ll) {
keyinputs["CSVURL" + id] = ""; key["CSVURL" + id] = ""; CSV1 = 1;
keyinputs["CSVURL2" + id] = ""; key["CSVURL2" + id] = ""; CSV2 = 1;
}
if (s == 0 && l < ll) {
keyinputs["CUSTOMISE" + id] = ""; key["CUSTOMISE" + id] = "";
CUSTOMISE = 1;
keyinputs["TEMP" + id] = "CSV File Missing"; key["TEMP" + id] = "CSV File Missing";
data[i][data[0].indexOf("STATUS")] = "CSV File Missing";
s = 1;
}
}
if (s == 0) {
if (key["TEMP" + id] != data[i][data[0].indexOf("_uuid")]) {
keyinputs["TEMP" + id] = "Completed"; key["TEMP" + id] = "Completed";
data[i][data[0].indexOf("STATUS")] = "Completed";
};
}
/*Sheduling tasks*/
{
if (year != 2017 && CUSTOMISE == 1) {
if (key["UN" + id] == null) {
var usernamenew = data[i][data[0].indexOf("Username")]; keyinputs["UN" + id] = data[i][data[0].indexOf("Username")];
key["UN" + id] = data[i][data[0].indexOf("Username")];
} else { usernamenew = key["UN" + id]; }/*FOR THE FIRST TIME*/
SCHEDULE("CUSTOMISE", data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")],
data[i][data[0].indexOf("formid")],
data[i][data[0].indexOf("_id")],
data[i][data[0].indexOf("_uuid")],
key["UNO" + id],
usernamenew);
}
if (TEMPLATE == 1) {
var filename = data[i][data[0].indexOf("CONTACT_INFORMATION/Country")] + "_" + data[i][data[0].indexOf("CONTACT_INFORMATION/D_Station")];
SCHEDULE("TEMPLATEREPORT", data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")],
data[i][data[0].indexOf("formid")],
data[i][data[0].indexOf("_id")],
filename);
}
if (COUNTRYNOTE == 1) {
var usernamex;
var dutystationx;
var usernamex = data[i][data[0].indexOf("Username")];
var dutystationx = data[i][data[0].indexOf("CONTACT_INFORMATION/D_Station")];
SCHEDULE("ANALYSISNOTEEXTRACT", year,
data[i][data[0].indexOf("CONTACT_INFORMATION/Country")],
usernamex,
dutystationx
, data[i][data[0].indexOf("_id")]);
}
if (TEMPLATESUMMARYTABLE > 0 && TEMPLATESUMMARYTABLEyear != data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")]) {
SCHEDULE("TABLEUPDATE", data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")]);
TEMPLATESUMMARYTABLEyear = data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")];
}
}
/*Display of updated status*/
{
control.getRange(i + 1, c1).setValue(data[i][data[0].indexOf("STATUS")]);
if (yearcheck(data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")]) == 0) {
keyinputs["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
key["UUIDBEFORE" + id] = data[i][data[0].indexOf("_uuid")];
keyinputs["CUSTOMISE" + id] = "OK"; key["CUSTOMISE" + id] = "OK";
}
}
/*URL updates*/
{
var tr = 'TEMPR' + id;
if (key[tr] != "" && key[tr] != null && TEMPR == 0) {
control.getRange(i + 1, c3).setValue('=hyperlink("' + key[tr] + '","READY")');
} else {
control.getRange(i + 1, c3).setValue("");
}
var csv = 'CSVURL' + id;
if (key[csv] != "" && key[csv] != null && CSV1 == 0) {
control.getRange(i + 1, c4).setValue('=hyperlink("' + key[csv] + '","READY")');
} else {
control.getRange(i + 1, c4).setValue("");
}
var csv2 = 'CSVURL2' + id;
if (key[csv2] != "" && key[csv2] != null && CSV2 == 0) {
control.getRange(i + 1, c5).setValue('=hyperlink("' + key[csv2] + '","READY")');
} else {
control.getRange(i + 1, c5).setValue("");
}
var csv3 = 'CSVURL3' + year;
if (key[csv3] != "" && key[csv3] != null) {
control.getRange(i + 1, c55).setValue('=hyperlink("' + key[csv3] + '","READY")');
} else {
control.getRange(i + 1, c55).setValue("");
}
var csv4 = 'CSVURL4' + id;
if (key[csv4] != "" && key[csv4] != null) {
control.getRange(i + 1, c7).setValue('=hyperlink("' + key[csv4] + '","READY")');
} else {
control.getRange(i + 1, c7).setValue("");
}
var csv5 = 'CSVURL5' + year;
if (key[csv5] != "" && key[csv5] != null) {
control.getRange(i + 1, c8).setValue('=hyperlink("' + key[csv5] + '","READY")');
} else {
control.getRange(i + 1, c8).setValue("");
}
var cn = 'CNOTE' + id;
if (key[cn] != "" && key[cn] != null) {
control.getRange(i + 1, c6).setValue('=hyperlink("' + key[cn] + '","READY")');
} else {
control.getRange(i + 1, c6).setValue("");
}
SpreadsheetApp.flush();
}
}
}
}
/**********************************/
|
Username access permission check
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /*Username access permission check*/
{
var users = KOBOFORM(key["APITOKEN2"]);
for (i = 2; i < data.length; i++) {
if (dataid != null) { if (data[i][data[0].indexOf("_id")] != dataid) { continue; } }
if (data[i][data[0].indexOf("formid")] == "") { continue; }
var kkk = 'UNA' + data[i][data[0].indexOf("_id")];
/*Skip Updating or outside of Autoyear*/
if (data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")] == 2017 || yearcheck(data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")]) == 0) {
control.getRange(i + 1, c2).setValue("");
continue;
}
control.getRange(i + 1, c2).setValue("Pending Authorisation");
var verification = 0;
var usernametemp;
for (u = 0; u < users.length; u++) {
if (users[u]["title"].indexOf(data[i][data[0].indexOf("PROGRAMME_SYNOPSIS/PROGRAMME_INFORMATION/Year")]) == -1) {
continue;
};
/*ATTENTION: This above will exclude the 2017 template forcefully*/
for (uu = 0; uu < users[u]["users"].length; uu++) {
if (users[u]["users"][uu]["user"] != data[i][data[0].indexOf("Username")]) {
continue;
}
if (users[u]["users"][uu]["permissions"].length == 1 && users[u]["users"][uu]["permissions"] == "report_xform") { verification++; usernametemp = users[u]["users"][uu]["user"]; continue; }
if (users[u]["users"][uu]["permissions"].length == 1 && users[u]["users"][uu]["permissions"] != "report_xform") { verification = verification + 2; usernametemp = users[u]["users"][uu]["user"]; continue; }
if (users[u]["users"][uu]["permissions"].length > 1) { verification = verification + 2; usernametemp = users[u]["users"][uu]["user"]; continue; }
}
}
if (verification == 3) {
control.getRange(i + 1, c2).setValue("OK : " + usernametemp);
if (data[i][data[0].indexOf("USER_ACCESS")].indexOf("OK") == -1 && dataid != null && key["EMAIL"] == "ON") {
generateEmailNotice(id,
"User Access Granted in Kobo",
"Username: " + usernametemp + " has been authorised to access Customised Surveys in Kobo",
"0",
"Thank you very much for submitting the " + year + " " + key["SECTOR"] + " Monitoring Template." +
"<br><br>We confirm the receipt and please find the PDF version for your kind attention." +
"<br><br>Please kindly let us know in case you find any information missing, or parts not reflecting correctly what you submitted." +
"<br><br>Based on the information submitted in this template, your customized surveys are developed. Please kindly find your ID and password to access your Customised Beneficiary and Partner Surveys." +
"<br><br><b>Username</b>: " + usernametemp + " (<i>Note: all in lowercase</i>)" +
"<br><b>Password</b>: 1951" +
"<br>Please keep these credentials confidential." +
"<br><br>To access your surveys, please install Apps called “KoBoCollect” in your smartphone/tablets (<i>Note: Android only</i>) and download your customized survey, by executing the following 2 tasks explained in the Kobo User guidance." +
"<br><br><b>Step.1</b>: Installing KoboCollect in your mobile" +
"<br><b>Step.2</b>: Setting up your customised beneficiary / partner survey" +
"<br> <b>2a</b>. Training survey (For Training Only)" +
"<br><br>Should you encounter any technical challenges, please do not hesitate to contact us." +
"<br><br>We would like to organize a brief training session on how to use Kobo and the customised surveys through a skype or Webex call in the coming weeks. Please let us come back to you with more details on this." +
"<br><br>Thank you and best regards,");
}
}
else if (verification > 0) { control.getRange(i + 1, c2).setValue("Review : " + usernametemp); }
}
}
|