Extract gmail data (day of last contact) to google sheet - google-sheets

I m trying to collect on a google spreadsheet the dates of the latest activity related to one specific email adresse.
So ideally, I'd like to input a list of email adresses and get on the next column the date of the latest interaction (incoming or outcoming email)
I've been looking for an add-on, but no luck for now.
Anyone can help ?
Many thanks,
Jeremy

Solution
This can easily be achieved using Apps Script. In the Spreadsheet with your email addresses go to Tools->Script Editor and use the code below by running the script (Run->Run function -> myFunction).
This is the piece of code that performs what you were trying to achieve with comments explaining how it works:
function myFunction() {
// Get the value in the cell A1 (which will have the email to check the latest interaction)
var ss = SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('A1').getValue();
// Search the date of the last message of the search from the email in cell A1 and log it
var latestEmail = GmailApp.search('from:"'+ss+'"')[0].getLastMessageDate();
Logger.log(latestEmail);
// Print the date on the cell to the right
SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('B1').setValue(latestEmail);
}
I hope this has helped you. Let me know if you need anything else or if you did not understood something. :)

Related

How to log users email in Google Apps Script

I'm trying to make a script that logs the date and time, and a user's email address when a button is pressed in Google Sheets. I can get the date and time values printed but whenever the button is pushed it just returns "Logger" instead of an email address. I'm also struggling to figure out how to change which cell the value is returned in, as the sheet is designed to log many users. Here's what I have so far, any help is appreciated.
edit, I've gotten the script to insert the user's email into a specified cell. Now I'm just wondering how to make it so it inserts the date and email into the next available row.
function setDate() {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1").getRange("N2").setValue(new Date());
var email = Session.getActiveUser().getEmail();
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Form Responses 1").getRange("O2").setValue(email);
}
Refer to getActiveUser()
If security policies do not allow access to the user's identity, User.getEmail() returns a blank string. [...] However, these restrictions generally do not apply if the developer runs the script themselves or belongs to the same Google Workspace domain as the user.

Capture text input and save it , dialogflow inline editor

I have created a chatbot with dialogflow using the inline editor. It works perfect right now.
My problem is, how to capture the message entered by the user? ie:
Imagine I have this conversation:
user: Good morning
bot: Hi, how can I help you...
mu purpose is to get the text:
Good morning.
Then, I'll store this statement into my database.
I want just a method to capture it. Can you tell me what I should write, please?
Example: if I want to capture a parameter , I write:
let ville = agent.parameters.ville;
In case of the whole text, what should I write?
To get the full content of the message the user said, use:
let query = agent.query

Bringing in a google form response to a sheet

Here is a copy of the sheets and form (form > go to live)
https://docs.google.com/a/ncsu.edu/spreadsheets/d/1mEz9mLEgP4Cfts2ZU6NwhNiL6xjWdFbt42RUj-RYbZw/edit?usp=sharing
So currently, I get responses in a different sheet. Ideally, I would get the response on the tracking sheet with the appropriate format for the dates. Additionally, I would like to keep the functionality of the tracking sheet which is to be able add in items by hand and not through the form. I currently have a script in place which auto-inputs the current date as the two separate formats.
So I'm looking for a solution which either takes in form response to the sheet and appropriate cells (the first empty cell). Or I'm looking to create a script which onEdit which when the form sheet is edited, will fetch the new response and copy it over appropriately onto the tacking sheet.
I have tried googling answers.. But I think I may be a failure at it since I wasn't able to really find a solution for this particular problem. Thank you in advance for the help!
form:
https://docs.google.com/forms/d/1AHSQrLkq3U7NJMvgWoH3lAygova7Mi4BaXHdROaaS2g/edit?usp=sharing
The script associated to this form should do the trick.
All the explanations on how to use it are in the response sheet

Refresh ImportHTML

I have a sheet that is importing data using ImportHTML. The data changes quite frequently, is there any way to have Google Sheets automatically refresh the data?
I tried adding & year(now()) & month(now()) & day(now()) & hour(now()) & minute(now()), to the formula but I get the following error:
This function is not allowed to reference a cell with NOW(), RAND(), or RANDBETWEEN()
"Any way"? Yes, but as Mogsdad has mentioned 'round these parts before, "Since the retirement of the GOOGLECLOCK function, there is no formula that will trigger automatic recalculation."
Using Google Apps Script and something like...
function getData() {
var queryString = Utilities.formatDate(new Date(), "GMT", "yyyyMMddHHmmss");
var cellFunction = '=IMPORTHTML("<your-url>?' + queryString + '","<your-query>",<your-index>)';
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("<your-sheet>").getRange('<your-cell>').setValue(cellFunction);
}
...should get you there. After saving, naming, and authorizing the script, set up a trigger so it runs/refreshes the data as frequently as you'd like.
Very late to the question. I recently had to do a similar thing. I thought I'd write something up here for others to find useful..hopefully.
My Use Case:
I wanted my google sheet to call IMPORTDATA on a specific url every few minutes because the data stored against that url was being changed by a Timer Trigger and an Http Trigger Azure Function.
Basically, I wanted my google sheet to get refreshed every 5 minutes because I knew the data against the url keeps changing.
What I Tried:
I started out with a similar script to what #greg alluded. (Cheers for that.)
I setup a timer trigger for that script to be 5 minutes. All looked hunky-dory.
Issues:
I realised that setting the function as a value on the cell caused the function to run only at the start when the sheet was empty. The second time the trigger hit, the sheet did not get refreshed.
So I tried
cell.setValue("");
cell.setValue('=IMPORTDATA("my-url")');
No Luck.
The sheet did not get refreshed with the new data. It seemed as if the sheet saw that the value-to-set in the cell is the same as the existing value, so it did not bother re-running the function.
To confirm my hypothesis,
I manually tried:
Cut the IMPORTDATA function from the google sheet cell.
Paste the value back into the cell.
The sheet did not get refreshed.
But when I manually tried:
Remove/Change the url from/in the cell. Hit Enter.
Paste the formula again in the cell. Hit Enter.
This worked. So, it seems that cell.SetValue() or even cell.setFormula() just doesn't re-run the function I was setting because the same function existed in the cell to start with.
My Solution best suited to my use-case:
Since the data against the url, I was pointing to, was already in CSV format,
I did something like this:
var firstSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var text = UrlFetchApp.fetch(url).getContentText(); //gets the data.
var csv = Utilities.parseCsv(text); //parses the data.
var range = firstSheet.getRange(1, 1, csv.length, 17) //getting the range.
range.setValues(csv); //setting the data.
I'm basically grabbing the data from the url and putting it into the sheet on timer instead of calling the IMPORTDATA function since that approach didn't quite work out for me.
You could do a similar thing, assuming you want to get some sort of table or chart content and save the values to your sheet.

Sharepoint 2007 - Displaying current date in a custom list

I have been reading blog after blog about displaying the current date in a sharepoint list and nothing seems to work. I do not have administrative rights to my sharepoint server but I was able to combine some java scripts and was able to display the current date (that change each day) in a custom list. My problem is that my success is only half full and I need someone's help to figure out the rest. Here it goes:
1. I created a column in my list called "DateField", I use the calculation field with ="<B></B>
as the calculation
2. I created a Content Edit WebPart and use the source below:
<script type="text/javascript">
var currentTime = new Date()
var month = currentTime.getMonth()+1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var CurrentDate = month + "/"+ day + "/" + year
$(document).ready(function(){
$(".ms-vb2:contains('<B')").each(function(){
var tempB = document.createElement ("B");
tempB.style.cursor = "pointer";
tempB.innerHTML = $(this).text();
$(this).text(CurrentDate);
$(this).append(tempB);
});
});
</script>
The script works and the date changes each day but I cannot use the date for anything. For some reason it only sees the HTML tags in the field but it displays the current date in the column on the list. Can someone help me figure out how I can store the actual date in the column?
Thanks
Ramon
If you want to store the current date field on the column to be reused
that means that you will have to modify all the items every day with today's date.
Is that what do you really need ? it could be achieved with some ajax call to the web services (if you have update permissions for those items).
However I don't really understand your scenario.
Could you elaborate ?
My solution was to create a custom field type for the column, which would always return the current date (and time if needed). This produced the desired effect - the current date (and time) would be displayed on the front end, but still available for use in other fields in the back end.
A quick Google for examples (my code is two jobs behind me, and I haven't touched MOSS in 6 months) gives me http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/
Good luck!
Regards
Moo

Resources