TRIGGERS Component

This is the image caption

The block diagram of TRIGGERS Component

Warning

Update the function names

Function triggerAction4Hours

triggerAction4Hours()

The function synchronizes the forms and data from Kobotoolbox (ALLFORMS()) in automatic mode,triggers every 4 hours

alternate text

The block diagram of triggerAction4Hours function

Warning

Update the function names

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function triggerAction4Hours() {
    var verify = getData("TASKS");
    if (verify[verify.length - 1][0] == "") {
        Browser.msgBox("To refresh, currently pending tasks must be completed first. Try again later.");
        return;
    }

    synchronizeAllForms();
    updateOnCustomisation();
}

Function triggerExecuteTask5Minutes

triggerExecuteTask5Minutes()

The function executes a task in task lists

alternate text

The block diagram of triggerExecuteTask5Minutes function

1
2
3
function triggerExecuteTask5Minutes() {
    EXCUTETASK();
}

Function triggerActionDaily

triggerActionDaily()

The function checks the data submission status, exports data from Kobo, creates sample profile and email,cleans/harmonise data, creates/updates a Country Analysis note

alternate text

The block diagram of triggerActionDaily function

1
2
3
4
function triggerActionDaily() {
    //ANALYSISDATAALL();
    updateDataHarmonizeDatabridge();
    TEMPLATEALL();

Function scheduleReminder [Triggers.gs]

scheduleReminder()

The Function schedules a reminder

1
2
3
function scheduleReminder() {
    SCHEDULE("REMINDER");
}

Function changeTrigger

changeTrigger(pkey)

The Function changes the triggers depending on the selected mode. (three possible triggers : triggerAction4Hours, triggerExecuteTask5Minutes and triggerActionDaily).

Arguments
  • pkey (Object) – the list of key properties and their values

Returns

keyinputs – the list of key parameters.

alternate text

The block diagram of DELETETRIGGER function

 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
function changeTrigger(pkey) {
    key = pkey;
    var CONTROL = ss.getSheetByName("CONTROL");
    var AT = "AUTO";
    var TRIGGER = key[AT];
    /* 
    if (TRIGGER == "FAST") {
    
    var triggers = ScriptApp.getProjectTriggers();
    
    for (var i = 0; i < triggers.length; i++) {
    if (triggers[i].getHandlerFunction() == "MAKEXML" || triggers[i].getHandlerFunction().indexOf("DELETEDATA") > -1) { continue; }
    ScriptApp.deleteTrigger(triggers[i]);
    }
    
    ScriptApp.newTrigger('showSidebar')
    .forSpreadsheet(ss)
    .openSidebar()
    .create();
    
    CONTROL.getRange(2, 1).setValue("AUTO OFF").setFontColor("red");
    keyinputs[AT] = "OFF";
    return (keyinputs);
    } */

    if (TRIGGER == null || TRIGGER == "OFF") {
        ScriptApp.newTrigger('triggerAction4Hours')
            .timeBased()
            .everyHours(4)
            .create();

        ScriptApp.newTrigger('triggerExecuteTask5Minutes')
            .timeBased()
            .everyMinutes(5)
            .create();


        ScriptApp.newTrigger('triggerActionDaily')
            .timeBased()
            .atHour(1)
            .everyDays(1)
            .inTimezone("Europe/Athens")
            .create();

        ScriptApp.newTrigger('scheduleReminder')
            .timeBased()
            .atHour(23)
            .everyDays(1)
            .inTimezone("Europe/Athens")
            .create();

        ScriptApp.newTrigger('Resetemail')
            .timeBased()
            .atHour(0)
            .everyDays(1)
            .inTimezone("Europe/Athens")
            .create();

        CONTROL.getRange(2, 1).setValue("AUTO ON").setFontColor("green");
        keyinputs[AT] = "NORMAL";
    }

    if (TRIGGER == "NORMAL") {
        var triggers = ScriptApp.getProjectTriggers();

        for (var i = 0; i < triggers.length; i++) {
            if (triggers[i].getHandlerFunction() == "MAKEXML" || triggers[i].getHandlerFunction().indexOf("DELETEDATA") > -1) { continue; }
            ScriptApp.deleteTrigger(triggers[i]);
        }

        ScriptApp.newTrigger('showSidebar')
            .forSpreadsheet(ss)
            .openSidebar()
            .create();

        CONTROL.getRange(2, 1).setValue("AUTO OFF").setFontColor("red");
        keyinputs[AT] = "OFF";
        return (keyinputs);

    }

Function adjustTrigger

adjustTrigger(pkey)

The function adjusts the triggers

Arguments
  • pkey (Object) – the list of key properties and their values

Returns

keyinputs – List of key 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function adjustTrigger(pkey) {
    if (pkey != null) { key = pkey };
    var CONTROL = ss.getSheetByName("CONTROL");
    var taskn = CONTROL.getRange(5, 1).getValue();

    var AT = "AUTO";
    var TRIGGER = key[AT];

    if (TRIGGER == "OFF") {
        return (keyinputs);
    }

    if (TRIGGER == null || taskn < 4) {
        var triggers = ScriptApp.getProjectTriggers();

        for (var i = 0; i < triggers.length; i++) {
            if (triggers[i].getHandlerFunction() == "triggerExecuteTask5Minutes") { ScriptApp.deleteTrigger(triggers[i]); }
        }

     
        ScriptApp.newTrigger('triggerExecuteTask5Minutes')
            .timeBased()
            .everyMinutes(5)
            .create();


        CONTROL.getRange(2, 1).setValue("AUTO SLOW").setFontColor("green");
        keyinputs[AT] = "NORMAL";
        key[AT] = "NORMAL";
    }

    if (taskn > 3) {

        var triggers = ScriptApp.getProjectTriggers();

        for (var i = 0; i < triggers.length; i++) {
            if (triggers[i].getHandlerFunction() == "triggerExecuteTask5Minutes") { ScriptApp.deleteTrigger(triggers[i]); }
        }

      
        ScriptApp.newTrigger('triggerExecuteTask5Minutes')
            .timeBased()
            .everyMinutes(1)
            .create();


        CONTROL.getRange(2, 1).setValue("AUTO FAST").setFontColor("blue");
        keyinputs[AT] = "FAST";
        key[AT] = "FAST";
    }
    return (keyinputs);
}

Function resetEmail

resetEmail()

The function resets the emails. (Current quota for email recipients per day is 100)

Returns

message – JavaScript object representing an email message

1
2
3
4
5
function resetEmail() {
    var x = MailApp.getRemainingDailyQuota();
    if (x == 100) {
        MailApp.sendEmail("monitoringproject1951@gmail.com", "email resetting", "email resetting");
    }