-
Notifications
You must be signed in to change notification settings - Fork 0
/
markCompetency.js
153 lines (111 loc) · 4.37 KB
/
markCompetency.js
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
function giveTripDirector(){
const meta_key = "competency_indoor_trip_director"
const meta_value = "Signed Off"
giveCompetency(meta_key, meta_value)
}
function giveTripDirectorTraining(){
const meta_key = "competency_indoor_trip_director"
const meta_value = "In Training"
giveCompetency(meta_key, meta_value)
}
function giveTripDirectorToLearn(){
const meta_key = "competency_indoor_trip_director"
const meta_value = "Keen to Learn"
giveCompetency(meta_key, meta_value)
}
function giveTripDirectorToRemove(){
const meta_key = "competency_indoor_trip_director"
const meta_value = ""
giveCompetency(meta_key, meta_value)
}
function givePairing(){
const meta_key = "competency_indoor_pairing"
const meta_value = "Signed Off"
giveCompetency(meta_key, meta_value)
}
function givePairingTraining(){
const meta_key = "competency_indoor_pairing"
const meta_value = "In Training"
giveCompetency(meta_key, meta_value)
}
function givePairingToLearn(){
const meta_key = "competency_indoor_pairing"
const meta_value = "Keen to Learn"
giveCompetency(meta_key, meta_value)
}
function giveFloorwalker(){
const meta_key = "competency_indoor_floorwalker"
const meta_value = "Signed Off"
giveCompetency(meta_key, meta_value)
}
function giveAnnouncements(){
const meta_key = "competency_indoor_announcements"
const meta_value = "Signed Off"
giveCompetency(meta_key, meta_value)
}
function giveCheckIn(){
const meta_key = "competency_indoor_checkin"
const meta_value = "Signed Off"
giveCompetency(meta_key, meta_value)
}
function giveCompetency(meta_key,meta_value){
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('Volunteering');
var active_range = sheet.getActiveRange();
var currentRow = active_range.getRowIndex();
//var currentRow = "18";
console.log(currentRow);
//var meta_key = "competency_indoor_trip_director"
//var meta_value = "Signed Off"
if(currentRow <=2){Browser.msgBox('Select an actual signup', Browser.Buttons.OK); return;}
if(currentRow >=100){Browser.msgBox('Select an actual signup', Browser.Buttons.OK); return;}
var user_id = sheet.getRange(currentRow, 20,1,1).getValue(); /// get submission ID 1 BV ( was 67)
var first_name = sheet.getRange(currentRow, 1,1,1).getValue(); /// get submission ID 1 BV ( was 67)
//console.log(user_id);
if(user_id === "" || user_id === "user_id"){Browser.msgBox('No User ID Found', Browser.Buttons.OK); return;}
if (Browser.msgBox("Given a competency to " +first_name + "? \n User " + user_id, Browser.Buttons.OK_CANCEL) == "ok") {
let cc_attendance_setter = Session.getActiveUser().getEmail();
//let metakey = "milestones_3_badge"
//let metavalue = "given"
let datetime = Date.now();
//Logger.log(datetime);
let meta_key_given_at = meta_key + "_marked_given_at"
let meta_key_given_by = meta_key + "_marked_given_by"
var data = {"meta_data": [
{"key": meta_key,
"value": meta_value},
{"key": meta_key_given_at,
"value": datetime},
{"key": meta_key_given_by,
"value": cc_attendance_setter }
],
};
let returndata = pokeToWooUserMeta(data, user_id); //returns JSON object
//returndata = returndata.getContentText();
//returndata= JSON.parse(returndata)
console.log(returndata);
//Logger.log("type " + typeof(returndata)); // type object
//Logger.log(returndata.data); // Logging output too large. Truncating output. {"id":52,"date_created":"2021-08-27T23:24:39","date_created_gmt":"2021-08-27T22:24:39","date_modified":"2022-11-23T11:51:41", etc etc etc
//Logger.log(returndata[0]); //null
//Logger.log("type " + typeof(returndata.id)); //type undefined
//Logger.log(returndata.data.id); //null
let search = returndata.meta_data.find(({key}) => key == meta_key)?.value;
//Logger.log(search);
if (search === meta_value){
sheet.getRange(currentRow, 2,1,1).setValue("Given"); // paste the blank variables into the cells to delete contents
sheet.getRange(currentRow, 15,1,1).setValue(meta_key);
sheet.getRange(currentRow, 16,1,1).setValue(meta_value); // paste the blank variables into the cells to delete contents
return meta_value
}
else {
Logger.log("ERROR" + search);
return "ERROR" + search
}
return "ERROR"
}
//Logger.log(returnvalue.meta_data);
//Logger.log(" type " + typeof(returnvalue.meta_data));
//Logger.log(JSON.parse(returnvalue));
//Logger.log(JSON.stringify(returnvalue.meta_data));
//return returndata;
}