|
| 1 | +fn(state => { //Mapping table to map Kobo field CHOICES to Asana custom_fields_choices gids |
| 2 | + const formatMapping = { |
| 3 | + |
| 4 | + SubmissionType_Grievance: '1208823831241793', |
| 5 | + SubmissionType_Suggestion: '1208823831314328', |
| 6 | + 'SubmissionType_Test case': '1208823831314329', |
| 7 | + SubmissionType_Question: '1208823831314330', |
| 8 | + Classification_Boundary: '1207934444664901', |
| 9 | + Classification_Comment: '1207064126306000', |
| 10 | + 'Classification_Human Resources': '1206208252500541', |
| 11 | + 'Classification_HWC (Human-Wildlife Conflict)': '1204269608862904', |
| 12 | + 'Classification_Illegal Activity': '1204269617420858', |
| 13 | + 'Classification_Management ': '1204269617420857', |
| 14 | + 'Classification_PI & NR (Project Implementation & Natural Resource Management)': '1204269608862903', |
| 15 | + 'Classification_Positive Feedback': '1204269617420859', |
| 16 | + Classification_Question: '1207064126305999', |
| 17 | + 'Classification_Request for assistance': '1204269617420968', |
| 18 | + 'Classification_Safeguards & Human Rights': '1204269608862902', |
| 19 | + Classification_Suggestion: '1207064073157821', |
| 20 | + Classification_Other: '1204269617420860', |
| 21 | + 'Classification_Not eligible': '1207724727681221', |
| 22 | + Country_Bolivia: '1208823831314340', |
| 23 | + Country_Brazil: '1208823831314341', |
| 24 | + Country_Colombia: '1208823831314342', |
| 25 | + Country_Ecuador: '1208823831314343', |
| 26 | + Country_Peru: '1208823831314344', |
| 27 | + Country_Indeterminado: '1208823831314345', |
| 28 | + Donor_AFD: '1207470695842883', |
| 29 | + Donor_BAF: '1207470914898964', |
| 30 | + Donor_BEF: '1207470928895774', |
| 31 | + Donor_EU: '1207470928895775', |
| 32 | + Donor_GEF: '1207470928895776', |
| 33 | + Donor_Hempel: '1207942941061344', |
| 34 | + Donor_INL: '1207470928895777', |
| 35 | + Donor_KFW: '1207942941061345', |
| 36 | + Donor_LLF: '1207470928895778', |
| 37 | + Donor_NOAA: '1207470928895779', |
| 38 | + Donor_MACP: '1207470928895780', |
| 39 | + 'Donor_REDD+': '1207470928895781', |
| 40 | + Donor_USAID: '1207470928895782', |
| 41 | + 'Donor_World Bank': '1207551210258645', |
| 42 | + WcsStaff_Yes: '1208823831341595', |
| 43 | + WcsStaff_No: '1208823831341596', |
| 44 | + ReportFormat_InPerson: '1202330347493011', |
| 45 | + ReportFormat_FocalPoint: '1207724960884497', |
| 46 | + ReportFormat_VoiceCall: '1202330347494027', |
| 47 | + ReportFormat_Hotline: '1202330347501419', |
| 48 | + ReportFormat_TextMessage: '1202330347498273', |
| 49 | + ReportFormat_SuggestionBox: '1202330347499327', |
| 50 | + ReportFormat_Email: '1202330347502485', |
| 51 | + ReportFormat_Letter: '1202330347503544', |
| 52 | + ReportFormat_OnlineForm: '1207934414764297', |
| 53 | + ReportFormat_Other: '1203830536105154', |
| 54 | + ReportFormat_Prospecting: '1208419056473280', |
| 55 | + Anonymous_Yes: '1203977086782816', |
| 56 | + Anonymous_No: '1208270620741491', |
| 57 | + Gender_male: '1202330737362427', |
| 58 | + Gender_female: '1202330737362428', |
| 59 | + 'Gender_mixed_gender': '1202330737362429', |
| 60 | + 'Gender_unknown_gender': '1202330737362430', |
| 61 | + IndigenousPeople_Yes_ips: '1202330755980982', |
| 62 | + IndigenousPeople_No_ips: '1202330755984093', |
| 63 | + IndigenousPeople_unknown_ips: '1202330755985164', |
| 64 | + IndigenousPeople_mixed_group: '1207724962870243', |
| 65 | + 'Age_<18': '1202330714895607', |
| 66 | + 'Age_19-35': '1202330714895608', |
| 67 | + 'Age_36-50': '1202330714895609', |
| 68 | + 'Age_>50': '1202330714895610', |
| 69 | + Age_mixed_age: '1202330714895611', |
| 70 | + Age_unknown_age: '1202330714895612', |
| 71 | + GrievanceAgainst_Wcs: '1202330466059593', |
| 72 | + GrievanceAgainst_GovernmentPartner: '1202330466059594', |
| 73 | + GrievanceAgainst_PrivateSectorPartner: '1202330466059595', |
| 74 | + GrievanceAgainst_CivilSocietyPartner: '1202330466059596', |
| 75 | + GrievanceAgainst_NotWcsAndNotAWcsPartner: '1202330466059597', |
| 76 | + ConfidentialitySensitivity_Yes: '1202330821410493', |
| 77 | + ConfidentialitySensitivity_No: '1202330821410494' |
| 78 | + }; |
| 79 | + state.inputData = state.data; |
| 80 | + return { ...state, formatMapping }; |
| 81 | +}); |
| 82 | + |
| 83 | +// ✅ SEARCH TASKS IN ASANA: |
| 84 | +// Update the custom_field GID (1201884379104074) to match the GrievanceID/CaseID field in your Asana workspace. |
| 85 | +// Also update `GrievanceID` key if your input uses a different name like CaseID or GrievanceId. |
| 86 | +request(`/workspaces/${state.configuration.workspaceGid}/tasks/search`, { |
| 87 | + query: { |
| 88 | + 'custom_fields.1201884379104074.value': $.inputData?.body?.GrievanceID, |
| 89 | + resource_subtype: 'default_task' |
| 90 | + } |
| 91 | +}); |
| 92 | + |
| 93 | +fn(state => { |
| 94 | + state.skipCreate = false; |
| 95 | + const tasks = state.data || []; |
| 96 | + // ✅ Ensure this matches the field name you used above. e.g., GrievanceID, CaseID |
| 97 | + const grievanceId = state.inputData?.body?.GrievanceID; |
| 98 | + |
| 99 | + if (tasks.length > 0) { |
| 100 | + console.log(`${tasks.length} task(s) found for GrievanceID ${grievanceId}. Skipping create.`); |
| 101 | + state.skipCreate = true; |
| 102 | + } |
| 103 | + return state; |
| 104 | +}); |
| 105 | + |
| 106 | +fnIf(!$.skipCreate, state => |
| 107 | + createTask({ |
| 108 | + name: $.inputData.body.GrievanceID, |
| 109 | + projects: [$.inputData.projectid], //to dynamically map project id, assuming it's defined in the Get job |
| 110 | + notes: $.inputData.body.DescriptioGrievance, |
| 111 | + custom_fields: { |
| 112 | + // Fields belonging to open-ended questions (qxns that accept free text input) |
| 113 | + '1203711959959076': $.inputData.body.StaffName, |
| 114 | + '1203712049265363': $.inputData.body.StaffEmail, |
| 115 | + '1208823831241787': $.inputData.body["Submission Date"], |
| 116 | + '1203712064304976': $.inputData.body.ReporterFullName, |
| 117 | + '1203712060006636': $.inputData.body.ReporterContactInformation, |
| 118 | + '1201884379104074': $.inputData.body.GrievanceId, |
| 119 | + '1203712112458773': $.inputData.body.AuthorityGrievanceReporter, |
| 120 | + '1202329899911619': $.inputData.body.WhereGrievance, |
| 121 | + '1208823831341587': $.inputData.body.WhenGrievance, |
| 122 | + '1203712125372990': $.inputData.body.PartiesInvolvedGrievance, |
| 123 | + '1203712145400954': $.inputData.body.LocalAuthoritiesContacted, |
| 124 | + '1208823831341575': $.inputData.body.DescriptioGrievance, |
| 125 | + '1203712150593482': $.inputData.body.HarmSuffered, |
| 126 | + '1203712149463009': $.inputData.body.ReliefRequested, |
| 127 | + '1208823831241782': $.inputData.body["OneDrive Folder"], |
| 128 | + '1203830309880883': $.inputData.body.WhatProject, |
| 129 | + '1208823831341580': $.inputData.body.Suggestion, |
| 130 | + |
| 131 | + // Fields belonging to questions with dropdown or multiple choice |
| 132 | + '1187328718760774': state => state.formatMapping["GrievanceStatus _" + $.inputData.body.GrievanceStatus], |
| 133 | + '1208823831241792': state => state.formatMapping["SubmissionType_" + $.inputData.body.SubmissionType], |
| 134 | + '1202593715272940': state => state.formatMapping["Grade_" + $.inputData.body.Grade], |
| 135 | + '1204269608862901': state => state.formatMapping["Classification_" + $.inputData.body.Classification], |
| 136 | + '1208823831314339': state => state.formatMapping["Country_" + $.inputData.body.Country], |
| 137 | + '1207470695842882': state => state.formatMapping["Donor_" + $.inputData.body.Donor], |
| 138 | + '1208823831341594': state => state.formatMapping["WcsStaff_" + $.inputData.body.WcsStaff], |
| 139 | + '1202330347491974': state => state.formatMapping["ReportFormat_" + $.inputData.body.ReportFormat], |
| 140 | + '1203977086782815': state => state.formatMapping["Anonymous_" + $.inputData.body.Anonymous], |
| 141 | + '1202330737362426': state => state.formatMapping["Gender_" + $.inputData.body.Gender], |
| 142 | + '1202330755979944': state => state.formatMapping["IndigenousPeople_" + $.inputData.body.IndigenousPeople], |
| 143 | + '1202330714895606': state => state.formatMapping["Age_" + $.inputData.body.Age], |
| 144 | + '1202330466059592': state => state.formatMapping["GrievanceAgainst_" + $.inputData.body.GrievanceAgainst], |
| 145 | + '1202330821410492': state => state.formatMapping["ConfidentialitySensitivity_" + $.inputData.body.ConfidentialitySensitivity], |
| 146 | + } |
| 147 | + }, |
| 148 | + state => { |
| 149 | + console.log(JSON.stringify(state.data, null, 2)); //log data |
| 150 | + return state; |
| 151 | + } |
| 152 | + ) |
| 153 | +) |
0 commit comments