-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattendeesAndRSVPs2ITJ.js
More file actions
410 lines (394 loc) · 12.4 KB
/
attendeesAndRSVPs2ITJ.js
File metadata and controls
410 lines (394 loc) · 12.4 KB
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/* This has been written for use in an Airtable automation. The source records
come from the Sessions table. The input fields are: Topics, and two links to
the People table: RSVPs, and Attendees. The goal is to combine the people in
RSVPs and Attendees into a single array of unique People recordIDs (not all
attendees rsvp & and not all rsvps attend the session, BUT either case is of
note for topic interest), then for each person, for each topic, send a record to
the Interest Topic Junction (ITJ) table.
With the automations' inputs, the data structure we're working with is an object
i.e.
{
input1: ...,
input2: ...,
...
}
e.g. per Airtable API field type's data structure
{
attendees: ["rec...", ...],
rsvps: ["rec...", ...],
topics: ["rec...", ...],
date: "YYYY-MM-DDTHH:MM:SS.mmmZ",
url: "https://...",
sessions: "rec...",
topicsText: "...\n..."
} */
// the input configuration for the Airtable automation script, per each
// triggering record. In the first exmple, there are four unique People
// recordIDs and two topics, for a rersult of eight combinations
/* ************************************************************ */
// Actual airscript automation code:
/* ************************************************************ */
// let inputConfig = input.config();
/* ************************************************************ */
const inputConfig = {
attendees: [
"recmx0FIxnKzdpfsa",
"reczna053dNuHuyeg",
"recLSx8btcYCrHRKZ"
],
rsvps: [
"reczna053dNuHuyeg",
"recLSx8btcYCrHRKZ",
"recCB9AHh1oG5FL0O",
],
topics: [
"recRPW5NZupTR8lhi",
"recP3osaF9eWEFG9s"
],
date: "2019-08-01T18:30:00.000Z",
url: "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
sessions: "recaFZcUmi4PFNEek",
topicText: "TESTY TEST TEST\nof multi line text\ncool"
};
// This alternate inputData is included for for testing the case where the input
// for RSVPs is an empty array
// const inputConfig = {
// attendees: [
// "recgWOWU4MUqyR0eG",
// "recKrZ6S8HQcIDckr",
// "rec0ymZI2oaXQSBDH",
// "recmx0FIxnKzdpfsa",
// "reczna053dNuHuyeg",
// "recLSx8btcYCrHRKZ"
// ],
// rsvps: [],
// topics: [
// "recRPW5NZupTR8lhi",
// "recP3osaF9eWEFG9s"
// ],
// date: "2019-08-01T18:30:00.000Z",
// url: "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
// sessions: "recaFZcUmi4PFNEek",
// topicText: "TESTY TEST TEST\nof multi line text\ncool"
// };
let inputConfig = input.config();
// console.log(inputConfig);
// Input variables
let attendees = inputConfig.attendees;
let rsvps = inputConfig.rsvps;
let topics = inputConfig.topics;
let date = inputConfig.date;
let url = inputConfig.url;
let sessions = inputConfig.sessions;
let topicText = inputConfig.topicText;
// console.log(attendees);
// console.log(rsvps);
// console.log(topics);
// console.log(date);
// console.log(url);
// console.log(sessions);
// console.log(topicText);
// placeholders for preparing write data
let allPeopleIDs = [];
let uniquePeopleIDs = [];
let uniquePeopleIDsWithoutCompany = [];
/* An empty array to hold the iterable, line item array of objects for writing to the ITJ */
let data = [];
/* vvv COMMENT THIS OUT TO RUN IN NODE vvv */
// The table we'll write to
let tableITJ = base.getTable("Interest Topic Junction");
// console.log(tableITJ);
/* ^^^ COMMENT THIS OUT TO RUN IN NODE ^^^ */
// add all the values from attendees and rsvps
allPeopleIDs.push(...attendees, ...rsvps);
// console.log(allPeopleIDs);
// Make a unique set and add that set's values to an array
uniquePeopleIDs.push(...new Set(allPeopleIDs));
console.log(uniquePeopleIDs);
/* vvv COMMENT ALL OF THIS OUT TO RUN IN NODE vvv */
// accessing records on the People table for weeding out THIS Company employees and test records
let tablePeople = base.getTable("People");
// console.log(getPeople);
let peopleQuery = await tablePeople.selectRecordsAsync({
sorts: [
{field: "When their record was created"}
],
fields: [
"Name",
"Companies"
]
});
// console.log(peopleQuery);
// console.log(peopleQuery.records); // <-- array of {id: "recID...", name: Firstname Lastname"} objects (if we didn't bring in the "Name" field, then the name: value would be "Unnamed record")
// Find the company
/* *************************************************************************************************************** */
// console.log(peopleQuery.getRecord('recZA4SBQFM55Uqfg').getCellValue("Companies")[0].name); // <-- 'Twitter'
// console.log(peopleQuery.getRecord('recZA4SBQFM55Uqfg').getCellValue("Name")); // <-- Sharon Ly
/* *************************************************************************************************************** */
/* ^^^ e.g. console.log(peopleQuery.getRecord(`${iterable}`).getCellValue("Companies")[0].name); ^^^ */
// Query to the people table to see if the personID has an THIS Company company or "example" name string
// If so, then preclude adding those to the unique array for the Interest Topic Junction.
// Also checks for where there is no company associated
uniquePeopleIDs.forEach(u => {
// console.log(`id: ${u} is ${peopleQuery.getRecord(u).getCellValue("Name")} who works at ${peopleQuery.getRecord(u).getCellValue("Companies")[0].name}`);
// console.log(peopleQuery.getRecord(u).getCellValue("Name").toLowerCase().includes('example'));
if(peopleQuery.getRecord(u).getCellValue("Companies") !== null) {
if (peopleQuery.getRecord(u).getCellValue("Companies")[0].name !== 'THIS Company') {
if(peopleQuery.getRecord(u).getCellValue("Name").toLowerCase().includes('example') !== true) {
uniquePeopleIDsWithoutCompany.push(u);
}
}
} else if (peopleQuery.getRecord(u).getCellValue("Name").toLowerCase().includes('example') !== true) {
uniquePeopleIDsWithoutCompany.push(u);
}
}
)
console.log(uniquePeopleIDsWithoutCompany);
/* ^^^ COMMENT ALL OF THIS OUT TO RUN IN NODE ^^^ */
/* vvv TO RUN IN NODE UNCOMMENT THIS vvv */
// uniquePeopleIDsWithoutCompany.push(...uniquePeopleIDs);
/* ^^^ TO RUN IN NODE UNCOMMENT THIS ^^^ */
/* Create (unique(rsvp,attendees) * topics) # of permutations. */
// iterate over Attendees
for (let u = 0; u < uniquePeopleIDsWithoutCompany.length; u++) {
// iterate over Topics
for (let t = 0; t < topics.length; t++) {
data.push(
{
fields: {
"People": [{id: uniquePeopleIDsWithoutCompany[u]}], // <-- link field
"Topics": [{id: topics[t]}], // <-- link field
"Source Table": {name: "Sessions"}, // <-- single-select field
"Source Date": date, // <-- date field
"Zapier Delivery": true, // <-- checkbox field
"Source Record URL": url, // <-- url field
"Sessions": [{id: sessions}], //<-- link field
"Raw Text": topicText // <-- newline separated text
}
}
);
}
}
// console.log(data);
// console.log(JSON.stringify(data));
// Apply that set of unique people per Sessions record to the People and Topic
// link fields along with some other data for delivery to ITJ.
// Throttle the updates to under 50 at a time
/* ************************************************************ */
while (data.length > 0) {
await tableITJ.createRecordsAsync(data.slice(0, 50));
data = data.slice(50);
}
/* ************************************************************ */
/* Example result
[
{
"fields": {
"People": [
{
"id": "recmx0FIxnKzdpfsa"
}
],
"Topics": [
{
"id": "recRPW5NZupTR8lhi"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "recmx0FIxnKzdpfsa"
}
],
"Topics": [
{
"id": "recP3osaF9eWEFG9s"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "reczna053dNuHuyeg"
}
],
"Topics": [
{
"id": "recRPW5NZupTR8lhi"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "reczna053dNuHuyeg"
}
],
"Topics": [
{
"id": "recP3osaF9eWEFG9s"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "recLSx8btcYCrHRKZ"
}
],
"Topics": [
{
"id": "recRPW5NZupTR8lhi"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "recLSx8btcYCrHRKZ"
}
],
"Topics": [
{
"id": "recP3osaF9eWEFG9s"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "recCB9AHh1oG5FL0O"
}
],
"Topics": [
{
"id": "recRPW5NZupTR8lhi"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"Zapier Delivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
},
{
"fields": {
"People": [
{
"id": "recCB9AHh1oG5FL0O"
}
],
"Topics": [
{
"id": "recP3osaF9eWEFG9s"
}
],
"Source Table": {
"name": "Sessions"
},
"Source Date": "2019-08-01T18:30:00.000Z",
"ZapierDelivery": true,
"Source Record URL": "https://airtable.com/appzuwjc0q5xR0RZU/tblBJYnbw6rry5vd0/viwAX0jOZKy4m7qIc/recaFZcUmi4PFNEek?blocks=hide",
"Sessions": [
{
"id": "recaFZcUmi4PFNEek"
}
],
"Raw Text": "TESTY TEST TEST\nof multi line text\ncool"
}
}
]
*/