-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupsert_MbeMountains
128 lines (123 loc) · 6.63 KB
/
upsert_MbeMountains
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
fn(state => { //Mapping table to map Kobo field CHOICES to Asana custom_fields_choices gids
const formatMapping = {
'Grade_Grade 0': '1202593715272941',
'Grade_Grade 1': '1202593715272942',
'Grade_Grade 2': '1202593715272943',
'Grade_Grade 3': '1202593715272944',
'Grade_Grade 4': '1202593715272945',
'Grade_Grade 5': '1202593715272946',
'Classification_Safeguards & HR': '1204269608862902',
'Classification_PI &NR': '1204269608862903',
Classification_HWC: '1204269608862904',
'Classification_Management ': '1204269617420857',
'Classification_Illegal Activity': '1204269617420858',
Classification_PFS: '1204269617420859',
'Classification_Request or Question': '1204269617420968',
Classification_Other: '1204269617420860',
'Classification_Human Resources': '1206208252500541',
SubmissionType_Grievance: '1202329899911646',
SubmissionType_Suggestion: '1202329899911647',
SubmissionType_Request: '1202329899911648',
SubmissionType_Feedback: '1202329899911649',
'SubmissionType_Test case': '1206023522074189',
ReportFormat_InPerson: '1202330347493011',
ReportFormat_VoiceCall: '1202330347494027',
ReportFormat_TextMessage: '1202330347498273',
ReportFormat_Email: '1202330347502485',
ReportFormat_PostalLetter: '1202330347503544',
ReportFormat_Other: '1203830536105154',
ReportFormat_SuggestionBox: '1202330347499327',
ReportFormat_Hotline: '1202330347501419',
SubmissionContext_individual: '1202330732062943',
SubmissionContext_group: '1202330732067344',
SubmissionContext_passive_observation: '1202330732068565',
Gender_male: '1202330737362427',
Gender_female: '1202330737362428',
Gender_mixed_gender: '1202330737362429',
Gender_unknown_gender: '1202330737362430',
'Age_<18': '1202330714895607',
'Age_19-35': '1202330714895608',
'Age_36-50': '1202330714895609',
'Age_>50': '1202330714895610',
Age_mixed_age: '1202330714895611',
Age_unknown_age: '1202330714895612',
GrievanceAgainst_Wcs: '1202330466059593',
GrievanceAgainst_GovernmentPartner: '1202330466059594',
GrievanceAgainst_PrivateSectorPartner: '1202330466059595',
GrievanceAgainst_CivilSocietyPartner: '1202330466059596',
GrievanceAgainst_NotWcsAndNotAWcsPartner: '1202330466059597',
DatePrecision_Yes: '1202330815421248',
DatePrecision_No: '1202330815421249',
ConfidentialitySensitivity_Yes: '1202330821410493',
ConfidentialitySensitivity_No: '1202330821410494',
Village_Abu: '1206427761204002',
'Village_Abu Bisu': '1206427761204003',
'Village_Kayan 1': '1206427761204004',
'Village_Kayan 2': '1206427761204005',
'Village_Wula 1': '1206427761204006',
'Village_Wula 2': '1206427761204007',
Village_Bukalum: '1206427761204008',
Village_Bambam: '1206427761204009',
'Village_Mbo-mkpang': '1206427761204010'
};
return { ...state, formatMapping };
});
upsertTask(
dataValue('projectid'), //to dynamically map project id, assuming it's defined in the Get job. This projectID must be originally added to the Job that fetches data from Kobo.
//'1201382240883590', //hardcoded project id
{
externalId: "name", // Asana external Id field name (e.g., 'gid')
data: {
name: state =>
//`Grievance ID: ${dataValue('body.GrievanceID')(state)} (KoboID:${dataValue('body._id')(state)})`,
`${dataValue('body.GrievanceId')(state)} (KoboID:${dataValue('body._id')(state)})`,
projects: state => [`${dataValue('projectid')(state)}`], //to dynamically map project id, assuming it's defined in the Get job
//projects: ['1201382240883590'], //hardcoded Asana project id for Template Project
notes: dataValue('Description'),
custom_fields: {
//This tells Asana what fields to update and how to locate them.
//The statements below apply to Asana Fields that are for OPEN ENDED
//i.e. They accept FREE TEXT INPUT from the Kobo Form
'1202329899911595': dataValue('body.CaseID'),
'1202329899911593': dataValue('body.StaffNameOWR'),
'1202329899911597': dataValue('body.StaffEmailOWR'),
'1202329899911599': dataValue('body.SubmissionDate'),
'1204987877735031': dataValue('body.DepositDate'),
'1204987880815869': dataValue('body.SuggestionBoxId'),
'1204987880815878': dataValue('body.SuggestionBoxGps'),
'1204987880815882': dataValue('body.BoxCollectionDate'),
'1202329899911605': dataValue('body.ReporterName'),
'1202329899911607': dataValue('body.ReporterContactInformationOWR'),
'1202329899911615': dataValue('body.AuthorityGrievanceReporterOWR'),
'1202329899911619': dataValue('body.WhereGrievanceOWR'),
'1202329899911623': dataValue('body.GrievanceDate'),
'1202329899911625': dataValue('body.PartiesInvolvedGrievanceOWR'),
'1202329899911627': dataValue('body.LocalAuthoritiesContactedOWR'),
'1202329899911631': dataValue('body.HarmSufferedOWR'),
'1202329899911633': dataValue('body.ReliefRequestedOWR'),
'1202329899911635': dataValue('body.OnlineFolder'),
'1204987880842598': dataValue('body.Location'),
//The statements below apply to Asana Fields that have multiplechoice / DropDown options
//i.e. They require that the user selects specific options from the Kobo Form dropdown list.
// These are the questions that require the MAPPING TABLES at the top of this page.
//The mapping key-value pairs are obtained using a console.log tht runs in the Fetch GID Job
/* '0000000000000000': dataValue('body.WhereGrievance'), */ //Grievance Date field missing in Asana
'1202593715272940': state => state.formatMapping["Grade_" + dataValue('body.Grade')(state)],
'1204269608862901': state => state.formatMapping["Classification_" + dataValue('body.Classification')(state)],
'1202329899911645': state => state.formatMapping["SubmissionType_" + dataValue('body.SubmissionType')(state)],
'1202330347491974': state => state.formatMapping["ReportFormat_" + dataValue('body.ReportFormat')(state)],
'1202330732061901': state => state.formatMapping["SubmissionContext_" + dataValue('body.SubmissionContext')(state)],
'1202330737362426': state => state.formatMapping["Gender_" + dataValue('body.Gender')(state)],
'1202330714895606': state => state.formatMapping["Age_" + dataValue('body.Age')(state)],
'1202330466059592': state => state.formatMapping["GrievanceAgainst_" + dataValue('body.GrievanceAgainst')(state)],
'1202330815421247': state => state.formatMapping["DatePrecision_" + dataValue('body.DatePrecision')(state)],
'1202330821410492': state => state.formatMapping["ConfidentialitySensitivity_" + dataValue('body.ConfidentialitySensitivity')(state)],
'1206427761204001': state => state.formatMapping["Village_" + dataValue('body.Village')(state)],
},
},
},
state => {
console.log(JSON.stringify(state.data, null, 2)); //log data
return state;
}
);