Skip to content

Commit 4713b6b

Browse files
committed
[email protected]'s change on OpenFn.org
1 parent 3ec8aa9 commit 4713b6b

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

form-sharing/4-upsertAsanaTask.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
//This job will add a task to Asana if a new Kobo form was shared
22
fn(state => {
3-
console.log('formLastModifiedDate:: ', state.formLastModified);
4-
const dueDate = new Date(new Date().getTime() + 5 * 24 * 60 * 60 * 1000)
5-
.toISOString()
6-
.split('T')[0];
3+
console.log('Preparing Form Sharing task updates for Asana... ');
74

8-
state.asanaTasks = state.activeForms.map(form => {
5+
state.asanaTasks = state.formsToCreate ? state.formsToCreate.map(form => {
6+
const dateModified = new Date(form.date_deployed);
7+
const deployedDatePlus5 = new Date(dateModified.getTime() + 5 * 24 * 60 * 60 * 1000)
8+
.toISOString()
9+
.split('T')[0];
910
return {
1011
name: `New form added to OpenFn: ${form.name}`,
1112
approval_status: 'pending',
1213
projects: ['1198901998266253'],
1314
assignee_section: '1207247884457665', //OLD General Section: '1203181218738601',
1415
assignee: '1208302456826465',
15-
due_on: dueDate,
16+
due_on: deployedDatePlus5,
1617
notes: `New form added to OpenFn: ${form.name} (uid: ${form.uid}). Please review the Google Sheet to (1) update columns L, N, & O, and (2) update column E (look for cells where it says "ADD MANUALLY" to add any values missing e.g., "Instance"): https://docs.google.com/spreadsheets/d/1s7K3kxzm5AlpwiALattyc7D9_aIyqWmo2ubcQIUlqlY/edit#gid=1559623602`,
1718
};
18-
});
19+
}) : [];
1920

2021
state.archivedFormsTasks = state.archivedForms.map(form => {
22+
const dateModified = new Date(form.date_modified);
23+
const modifiedDatePlus5 = new Date(dateModified.getTime() + 5 * 24 * 60 * 60 * 1000)
24+
.toISOString()
25+
.split('T')[0];
2126
return {
2227
name: `Form archived: ${form.name}`,
2328
projects: ['1198901998266253'],
2429
assignee_section: '1207247884457665', //OLD General Section: '1203181218738601',
2530
assignee: '1208302456826465',
26-
due_on: dueDate,
31+
due_on: modifiedDatePlus5,
2732
notes: `Kobo form was archived: ${form.name} (uid: ${form.uid}). Please review the Google Sheet to (1) confirm this is correct, (2) remove from the "Deployed" sheet if you want to remove from the OpenFn Sync, and (3) update notes in the "Archived" sheet: https://docs.google.com/spreadsheets/d/1s7K3kxzm5AlpwiALattyc7D9_aIyqWmo2ubcQIUlqlY/edit#gid=1559623602`,
2833
};
2934
});
3035

3136
console.log('# of New Form Asana Tasks to add:: ', state.asanaTasks.length);
32-
console.log('New form alert tasks to upsert:: ', state.asanaTasks);
37+
//console.log('New form alert tasks to upsert:: ', state.asanaTasks);
3338
console.log(
34-
'# of Archibed Form Asana Tasks to add:: ',
39+
'# of Archived Form Asana Tasks to add:: ',
3540
state.archivedFormsTasks.length
3641
);
3742
console.log(
@@ -58,4 +63,4 @@ each(
5863
externalId: 'name',
5964
data: state => state.data,
6065
})
61-
);
66+
);

0 commit comments

Comments
 (0)