2023-06-07 15:22:27 -04:00
|
|
|
/*
|
|
|
|
|
This script sends a daily reminder to the Sales and Marketing channel as to which
|
|
|
|
|
lines of data are unclean and not filled out. Currently, it is only pulling from the last 5 days.
|
|
|
|
|
This will be sent out between 3-4pm so that AEs can get their data in and clean before EOD.
|
2022-03-31 09:57:04 -04:00
|
|
|
Any questions or changes needed, see Norm.
|
2023-06-07 15:22:27 -04:00
|
|
|
Webhook URL in this sheet is for #sales-n-marketing channel.
|
2022-03-31 09:57:04 -04:00
|
|
|
*/
|
|
|
|
|
// Setup of the sheet
|
|
|
|
|
const sheet = SpreadsheetApp.getActiveSheet();
|
2022-02-24 09:18:06 -05:00
|
|
|
|
2022-03-31 09:57:04 -04:00
|
|
|
// Setup of the date range to compare. Currently, it is using 5 days until Present.
|
|
|
|
|
var now = new Date();
|
|
|
|
|
var formatNow = Utilities.formatDate(now, 'America/New_York', 'MM/dd/yyyy'); // Today
|
|
|
|
|
var daysToSubtract = 2;
|
|
|
|
|
var withinWeek = new Date(now.getTime()-daysToSubtract*(3600*24*1000));
|
|
|
|
|
var formatWeek = Utilities.formatDate(withinWeek, 'America/New_York', 'MM/dd/yyyy'); // 5 Days ago
|
2022-02-24 09:18:06 -05:00
|
|
|
|
2022-03-31 09:57:04 -04:00
|
|
|
// Counter for formatting the final list
|
|
|
|
|
var meetingCount = 0;
|
2022-02-23 17:40:01 -05:00
|
|
|
|
2022-03-31 09:57:04 -04:00
|
|
|
// Other empty Globals
|
|
|
|
|
var finalAEList;
|
|
|
|
|
var tagUsers;
|
2022-02-24 09:18:06 -05:00
|
|
|
|
2023-06-07 15:22:27 -04:00
|
|
|
/*
|
2022-03-31 09:57:04 -04:00
|
|
|
This function will create two empty arrays, one for the list of missed entries and one for tagging users in Slack
|
|
|
|
|
First, the function gets the data ranges in spreadsheed and adds those columns to an array index.
|
|
|
|
|
Second, the for loop cycles through the super long array (4 results per line). Based on the if statement,
|
2023-06-07 15:22:27 -04:00
|
|
|
the loop removes all arrays that don't fit the statement.
|
2022-03-31 09:57:04 -04:00
|
|
|
*/
|
|
|
|
|
function findMeetings() { // Setting up data range and empty arrays
|
|
|
|
|
var startRow = 2; // First row of data to process
|
|
|
|
|
var numRows = sheet.getLastRow()-1; // Number of rows to process
|
|
|
|
|
var dataRange = sheet.getRange(startRow, 1, numRows, sheet.getLastColumn());
|
|
|
|
|
var data = dataRange.getValues();
|
|
|
|
|
var slackingAEListOne = [];
|
|
|
|
|
var tagList = [];
|
2022-02-24 14:04:47 -05:00
|
|
|
|
2022-03-31 09:57:04 -04:00
|
|
|
for (i in data) { // For a data row within the entire data range
|
|
|
|
|
var row = data[i];
|
|
|
|
|
let attended = row[6]; // Column G
|
|
|
|
|
var name = row[1]; // Column - B
|
|
|
|
|
var date = Utilities.formatDate(row[3],'America/New_York','MM/dd/yyyy'); // Column - D
|
|
|
|
|
var company = row[4]; // Column - E
|
|
|
|
|
let missedEntries = [name, date, company, attended];
|
2023-06-07 15:22:27 -04:00
|
|
|
/*
|
|
|
|
|
Adding a For Loop will pull a result for EACH element, aka 4 results per line.
|
2022-03-31 09:57:04 -04:00
|
|
|
This pulls one for each group of missedEntries
|
|
|
|
|
This then removes the last value (attended, since we already know it is a blank), converts to a string,
|
2023-06-07 15:22:27 -04:00
|
|
|
and adds to a new array. The counter will compare if there is more than one entry in the array.
|
|
|
|
|
*/
|
2022-03-31 09:57:04 -04:00
|
|
|
if ((missedEntries[3] == "") && (missedEntries[1] >= formatWeek) && (missedEntries[1] <= formatNow)) {
|
|
|
|
|
meetingCount += 1;
|
|
|
|
|
missedEntries.pop();
|
|
|
|
|
missedEntries.toString();
|
|
|
|
|
slackingAEListOne.push(missedEntries);
|
|
|
|
|
//Logger.log(slackingAEListOne);
|
2022-02-24 14:04:47 -05:00
|
|
|
};
|
2022-03-31 09:57:04 -04:00
|
|
|
};
|
2023-06-07 15:22:27 -04:00
|
|
|
/* Now outside of the if statement:
|
2022-03-31 09:57:04 -04:00
|
|
|
the array is built, and we want each group to be on a new line, remove the commas and add a hyphen.
|
|
|
|
|
The counter counts if there is 1 or more meetings, or not. If 0, it sends a certain message, not tagging anyone.
|
2023-06-07 15:22:27 -04:00
|
|
|
If it is one or more, it splices by the first array (index 0), adds a new line, and replaces commans with hyphens.
|
2022-03-31 09:57:04 -04:00
|
|
|
*/
|
|
|
|
|
if (meetingCount >= 1) {
|
|
|
|
|
var slackingAEListTwo = slackingAEListOne.splice(0).join('\n');
|
|
|
|
|
var finalAEList = slackingAEListTwo.replace(/,/g, ' - ');
|
|
|
|
|
// This if statement is going to only tag those who appear in the previous list.
|
|
|
|
|
// No need to tag people who have done their work and contribute to clean data.
|
|
|
|
|
if (finalAEList.includes('Norm')) {
|
|
|
|
|
tagList.push('<@U020KRBDSDQ>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Dan')) {
|
|
|
|
|
tagList.push('<@U01P7DTFSQZ>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Charles')) {
|
|
|
|
|
tagList.push('<@U01286MQUS2>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Travis')) {
|
|
|
|
|
tagList.push('<@UFE3T14UX>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Nick')) {
|
|
|
|
|
tagList.push('<@U0276LMA70F>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Mike')) {
|
|
|
|
|
tagList.push('<@U027MAQUPM0>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Doug')) {
|
|
|
|
|
tagList.push('<@U02CK55FHFX>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Isabel')) {
|
|
|
|
|
tagList.push('<@U03019S7R6F>');
|
|
|
|
|
}
|
|
|
|
|
if (finalAEList.includes('Ryan')) {
|
|
|
|
|
tagList.push('<@U0325CWA3N3>');
|
|
|
|
|
}
|
|
|
|
|
var tagUsers = tagList.toString();
|
2023-06-07 15:22:27 -04:00
|
|
|
/*
|
|
|
|
|
Now, we're building the payload for the Slack Message.
|
2022-03-31 09:57:04 -04:00
|
|
|
This is very specific and prone to errors, so check that it works using Slack's tool:
|
|
|
|
|
https://app.slack.com/block-kit-builder/
|
|
|
|
|
|
|
|
|
|
Copy from Rich:
|
|
|
|
|
":rotating_light::rotating_light::rotating_light: New Meeting Tracker Alert! :rotating_light::rotating_light::rotating_light:
|
|
|
|
|
It's your daily reminder to update the new meeting tracker.
|
|
|
|
|
If you've been tagged, please address this by EOD."
|
|
|
|
|
*/
|
|
|
|
|
let payloadText =
|
|
|
|
|
{
|
|
|
|
|
"blocks": [
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": ":rotating_light::rotating_light::rotating_light: New Meeting Tracker Alert! :rotating_light::rotating_light::rotating_light:"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": "It's your daily reminder to update the new meeting tracker."
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": "If you've been tagged, please address this by EOD."
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": finalAEList // Sends list with AE, meeting date, and company
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": "In case you need it, here's a link to the sheet. :point_right:"
|
|
|
|
|
},
|
|
|
|
|
"accessory": {
|
|
|
|
|
"type": "button",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "plain_text",
|
|
|
|
|
"text": "Sales New Meeting Tracker",
|
|
|
|
|
"emoji": true
|
2022-02-24 09:18:06 -05:00
|
|
|
},
|
2022-03-31 09:57:04 -04:00
|
|
|
"value": "sales_tracker_link_123",
|
|
|
|
|
"url": "https://docs.google.com/spreadsheets/d/150nSuHQLJHpJaYdQ6KHeN7nQ6iexwtnQEpicM77PK8A/edit#gid=0 | First Meeting Tracker",
|
|
|
|
|
"action_id": "button-action"
|
2022-02-24 09:18:06 -05:00
|
|
|
}
|
|
|
|
|
},
|
2022-03-31 09:57:04 -04:00
|
|
|
{
|
|
|
|
|
"type": "divider"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": tagUsers // Tags with slack user numbers if they appear in finalSend
|
|
|
|
|
}
|
2022-02-24 09:18:06 -05:00
|
|
|
}
|
2022-03-31 09:57:04 -04:00
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
// This is standard operating procedure to creating the payload and destination
|
|
|
|
|
const webhook = "https://hooks.slack.com/services/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";
|
|
|
|
|
const options = {
|
2023-06-07 15:22:27 -04:00
|
|
|
method: "post",
|
2022-03-31 09:57:04 -04:00
|
|
|
contentType: "application/json",
|
|
|
|
|
muteHttpExceptions: true,
|
|
|
|
|
payload: JSON.stringify(payloadText),
|
|
|
|
|
};
|
|
|
|
|
const sendMsg = UrlFetchApp.fetch(webhook, options);
|
|
|
|
|
var respCode = sendMsg.getResponseCode();
|
|
|
|
|
//Logger.log(sendMsg); // Debug to confirm send
|
|
|
|
|
//Logger.log(respCode); // Debug to show errors, if any
|
|
|
|
|
/*
|
2023-06-07 15:22:27 -04:00
|
|
|
This is the else statement that sends a certain message not tagging anyone and saying that data is clean.
|
2022-03-31 09:57:04 -04:00
|
|
|
*/
|
|
|
|
|
} else {
|
2023-06-07 15:22:27 -04:00
|
|
|
let noMeetingMsg =
|
2022-03-31 09:57:04 -04:00
|
|
|
{
|
|
|
|
|
"blocks": [
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": ":star::star::star: New Meeting Tracker Alert! :star::star::star:"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"type": "section",
|
|
|
|
|
"text": {
|
|
|
|
|
"type": "mrkdwn",
|
|
|
|
|
"text": "Good job, everyone! All meetings from the last 5 days are up to date. Keep doing what you're doing!"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
};
|
|
|
|
|
// This is standard operating procedure to creating the payload and destination
|
|
|
|
|
const webhook = "https://hooks.slack.com/services/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";
|
|
|
|
|
const options = {
|
2023-06-07 15:22:27 -04:00
|
|
|
method: "post",
|
2022-03-31 09:57:04 -04:00
|
|
|
contentType: "application/json",
|
|
|
|
|
muteHttpExceptions: true,
|
|
|
|
|
payload: JSON.stringify(noMeetingMsg),
|
|
|
|
|
};
|
|
|
|
|
const sendMsg = UrlFetchApp.fetch(webhook, options);
|
|
|
|
|
var respCode = sendMsg.getResponseCode();
|
|
|
|
|
//Logger.log(sendMsg); // Debug to confirm send
|
|
|
|
|
//Logger.log(respCode); // Debug to show errors, if any
|
|
|
|
|
}
|
2022-10-31 10:47:43 -04:00
|
|
|
};
|