From 1ad3b0a6043e492cd641a2c9920a2be3ef1f4956 Mon Sep 17 00:00:00 2001
From: CherrelleTucker <106271365+CherrelleTucker@users.noreply.github.com>
Date: Tue, 3 Dec 2024 20:37:15 -0600
Subject: [PATCH] #74
Create ImplementationMasterContactList_ContactPopUp_gs
---
...mentationMasterContactList_ContactPopUp_gs | 139 ++++++++++++++++++
1 file changed, 139 insertions(+)
create mode 100644 ImplementationMasterContactList/ImplementationMasterContactList_ContactPopUp_gs
diff --git a/ImplementationMasterContactList/ImplementationMasterContactList_ContactPopUp_gs b/ImplementationMasterContactList/ImplementationMasterContactList_ContactPopUp_gs
new file mode 100644
index 0000000..bfb7475
--- /dev/null
+++ b/ImplementationMasterContactList/ImplementationMasterContactList_ContactPopUp_gs
@@ -0,0 +1,139 @@
+function onOpen() {
+ const ui = SpreadsheetApp.getUi();
+ ui.createMenu('Contact Tools')
+ .addItem('Show Consolidated Contact Info (Exit Views and Filters Before Selecting)', 'showContactInfo')
+ .addItem("Create targeted email list", "openDialog")
+ .addToUi();
+}
+
+function showContactInfo() {
+ const ui = SpreadsheetApp.getUi();
+ const range = SpreadsheetApp.getActiveSpreadsheet().getActiveRange();
+
+ // Ensure exactly one cell is selected in column C
+ if (range.getNumColumns() === 1 && range.getNumRows() === 1 && range.getColumn() === 3) { // Column C is index 2
+ const contactName = range.getCell(1, 1).getValue(); // Get value from column C
+
+ const contactInfo = getContactInfo(contactName);
+ const htmlOutput = HtmlService.createHtmlOutput(`
+
+
+ Contact Information for ${contactName}
+ ${contactInfo}
+
+ `)
+ .setWidth(800)
+ .setHeight(700);
+
+ ui.showModalDialog(htmlOutput, `Contact Information for ${contactName}`);
+ } else {
+ ui.alert('Please select a single cell in column C.');
+ }
+}
+
+function getContactInfo(contactName) {
+ const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('All_Contacts'); // Replace with your actual sheet name
+ if (!sheet) {
+ SpreadsheetApp.getUi().alert('The sheet named "All_Contacts" was not found. Please check the sheet name.');
+ return 'Sheet not found.';
+ }
+ const data = sheet.getDataRange().getValues();
+ const headers = data[1]; // Headers are in the second row (index 1)
+ const result = {};
+ const roleYearMap = new Map(); // To keep track of roles with combined years
+
+ // Initialize a result object for the specific columns we are interested in
+ const columnsToInclude = [0, 1, 5, 6, 7, 8, 12]; // Removed 'Assessment Solution' column and retained other necessary columns
+
+ columnsToInclude.forEach(index => {
+ result[headers[index]] = new Map(); // Use a Map to maintain the original value and its lowercased version
+ });
+
+ // Iterate through the rows, starting from the third row to skip headers
+ for (let i = 2; i < data.length; i++) { // Data starts from row 3 (index 2)
+ if (data[i][2] === contactName) { // Column C is index 2
+ for (const index of columnsToInclude) {
+ const header = headers[index];
+ let value = data[i][index];
+ if (value !== undefined && value !== null) {
+ // Ensure value is a string for trimming and comparison
+ value = String(value).trim();
+ const normalizedValue = value.toLowerCase(); // Normalize for comparison
+ if (!result[header].has(normalizedValue)) { // Check if the lowercased value is already stored
+ result[header].set(normalizedValue, value); // Store both the lowercased key and original value
+ }
+ }
+ }
+ // Collect roles separately and combine roles with multiple years
+ const role = data[i][3]; // Column D is index 3
+ const year = data[i][10]; // Column K is index 10
+ const assessmentSolution = data[i][1]; // Column B is index 1
+ if (role && year && assessmentSolution) {
+ const roleKey = `${role} in ${assessmentSolution}`;
+ if (!roleYearMap.has(roleKey)) {
+ roleYearMap.set(roleKey, new Set());
+ }
+ roleYearMap.get(roleKey).add(year);
+ }
+ }
+ }
+
+ // Format the roles into strings with combined years
+ let roles = [];
+ roleYearMap.forEach((years, roleKey) => {
+ const combinedYears = Array.from(years).sort().join(' and ');
+ roles.push(`- ${roleKey} in ${combinedYears}
`);
+ });
+
+ // Format the result object into a string for display with extra spacing
+ let formattedResult = '';
+
+ // Adding roles section if available with banding for visibility
+ if (roles.length > 0) {
+ formattedResult += `Roles:
`;
+ formattedResult += roles.join('') + '
';
+ }
+
+ // Adding other contact information
+ for (const [key, values] of Object.entries(result)) {
+ if (values.size > 0 && key !== 'Assessment Solution') { // Skip 'Assessment Solution' key
+ const uniqueValues = Array.from(values.values()); // Retrieve the original values from the Map
+ formattedResult += `${key}: ${uniqueValues.join(', ')}
`;
+ }
+ }
+
+ return formattedResult || 'No contact found.';
+}