Adding autocomplete email address list in google script - javascript

I am try to add autocomplete list email in my function. Right now, i key in the email address manually, so i have to write or copy all. it should be more efficient if the there autocomplete feature. Here is my code sample:
function getemail(){
var ui_user = SpreadsheetApp.getUi();
var result = ui_user.prompt("Enter Receiver Email:");
return result.getResponseText();
}
is GAS can search our contacts email address then query it all?

Yes, Google Apps Script could be used to search for contacts by using the Contacts Service but it's not possible to add autocomplete feature the Spreadsheet.Ui.prompt. In order to have that feature you will have to create a dialog by using HTML Service, client side code (HTML/CSS/JavaScript) and communicate this code with server code.

Related

Send Form with MailApp after fetching html. Embed Google Form into email. Generated email contains only text

I want to embed a Google form in an email and send it with MailApp. I'm attempting to use code found at: https://stackoverflow.com/a/23671529/4305236:
var form = FormApp.create('New Form');
....
var url = form.getPublishedUrl();
var response = UrlFetchApp.fetch(url);
var htmlBody = HtmlService.createHtmlOutput(response).getContent();
MailApp.sendEmail({
to: email,
subject: subject,
htmlBody: htmlBody,
});
...
The logs show all the html for the form.
However, when I run the code, the email just looks like text, with the links at bottom. When I "show original" in the email, though, all that html for the form seems to be there, like in the log...
Would greatly appreciate any help.
What generated form looks like, want this to be embedded in email:
What they are getting instead:
Answered here: https://stackoverflow.com/a/60749897/3383907.
Copy/pasting for history purposes:
When Google sends the form to folks directly and embeds the form in the email they are using their new offering called AMP. You can read more about it here:
https://developers.google.com/amp/
https://www.blog.google/products/g-suite/bringing-power-amp-gmail/
https://developers.google.com/gmail/ampemail/
The code you're using gets the raw HTML of the form as it would be rendered for a user in a browser. This code is not in AMP format. Ergo it will not do what you want.
If you want that AMP experience you will need to create the AMP email yourself.
I don't think FormApp has a programatic way to send the form to folks, like you can from https://docs.google.com/forms/.
I hope that helps.

Intergrate google adwords tracking with salesforce

im trying to integrate google adwords tracking with salesforce based on this
https://www.e-nor.com/blog/google-analytics/integrate-salesforce-and-google-analytics
i have created hidden fields in salesforce and add the code to the form and the js script to capture the values but i having problem i dont get any data coming in
test.php?utm_source=google&utm_medium=CPC&utm_campaign=test&utm_term=test
<input type="hidden" name="medium" id="medium" value="" />
<input type="hidden" name="source" id="source" value="" />
<input type="hidden" name="campaign" id="campaign" value="" />
<input type="hidden" name="term" id="term" value="" />
<script type="text/javascript">
var z = _uGC(document.cookie, '__utmz=', ';');
var source = _uGC(z, 'utmcsr=', '|');
var medium = _uGC(z, 'utmcmd=', '|');
var term = _uGC(z, 'utmctr=', '|');
var content = _uGC(z, 'utmcct=', '|');
var campaign = _uGC(z, 'utmccn=', '|');
var gclid = _uGC(z, 'utmgclid=', '|');
if (gclid !="-") {
source = 'google';
medium = 'cpc';
}
var csegment = _uGC(document.cookie, '__utmv=', ';');
if (csegment != '-') {
var csegmentex = /[1-9]*?\.(.*)/;
csegment = csegment.match(csegmentex);
csegment = csegment[1];
} else {
csegment = '';
}
function _uGC(l,n,s)
{
if (!l || l=="" || !n || n=="" || !s || s=="") return "-";
var i,i2,i3,c="-";
i=l.indexOf(n);
i3=n.indexOf("=")+1;
if (i > -1) {
i2=l.indexOf(s,i); if (i2 < 0){ i2=l.length; }
c=l.substring((i+i3),i2);
}
return c;
}
document.getElementById("medium").value =medium; /* Campaign_Medium */
document.getElementById("source").value =source; /* Campaign_Source */
document.getElementById("campaign").value =campaign; /* Campaign_CampaignName */
document.getElementById("term").value =term; /* Campaign_Term */
</script>
Okay, if I understand correctly you are trying to do a Web-to-Lead process and you want to capture the campaign information.
As I see it your current approach has two major flaws: The current version of Google Analytics (Universal Analytics, which uses the analytics.js tracking library) does not evaluate campaign information on the client side and does not store in in the cookie (UA uses a single cookie that only hold a client id).
But even if it did it would probably not help you with your Adwords data. Chances are pretty good that you have autotagging enabled, and in that you would not have campaign information for Adwords even with the old Google Analytics code. Adwords uses a Google Click id, or gclid, that is resolved into readable campaign parameters only after GA has retrieved to information from a linked Adwords account; on the client side you can only read the gclid parameter which does not help you.
So I suggest a different approach that should work well as long as you do not need the data in realtime, and as long as you a prepared to do some serverside programming instead of Javascript (which simply cannot do what you want). It goes basically like this:
Instead of sending campaign data along with your Web-To-Lead form you send just a unique id for the lead, and store in a custom field in Salesforce. You send the same id to Google Analytics as custom dimension that you have created before in a hit level scope by attaching a click event to the submit button (or submit event to the form), send a Google Analytics event and include the id as custom dimension.
Google Analytics needs a bit of processing time, so you wait until the next day. By then GA will have resolved the Adwords click ids into readable source/medium/campaign parameters (plus term and content if you need that, and it will have imported Adwords-related metrics).
You then query the Google Analytics Reporting API to retrieve the submit events from GA with your custom id and the campaign information. Then you send the campaign data via the Salesforce API to SF and store it in custom fields in your lead entities. Run the script once periodically and it will update all your leads with the data from GA.
The biggest drawback is possibly that API access is not available for all Salesforce editions. According to this knowledgebase article API access is enabled in Enterprise/Unlimited/Performance and Developer editions and can be enabled for a fee in the professional edition.
It has turned out to be impossible for me to cram instructions for the whole process into an stackoverflow post, so I wrote a tutorial that covers all steps. This requires some serverside programming - the tutorial uses python, and it should include enough information to get the program running even if you do not know Python. It's broken up into several parts, so you can skip the bits you are already familiar with.
Part 1 - Restating the Problem
Part 2 - The Programming Environment used in the tutorial
Part 3 - APIs and Authentication
Part 4 - Setting up Salesforce and Google Analytics
Part 5 - Libraries and example code
It might be that the links will be removed for being to self-promotional (they lead to my blog), but even so this post should give you an idea how to approach the problem.
I am not sure if you are using the correct codes and the correct sequence to do that, check my post here and use the same codes and instructions I am using to track Source, Medium, Campaign and Term, I fully tested it and it is working fine.
Your approach is correct, but I am not sure if you are trying to read the cookies before they are even created, if this is your landing page test.php?utm_source=google&utm_medium=CPC&utm_campaign=test&utm_term=test and it is the same page where you are trying to fill the hidden fields make sure the Javascript code/function that generates the cookies (function _uGC) get executed before the code that tries to fill in the fields

Google Apps Script Bad Value

I'm getting a "bad value on line 4"... I don't know why. I'm trying to make a Google sheet that automatically opens to an assigned tab based on gmail address for a large team. Please help!
function onOpen() {
var email = Session.getActiveUser().getEmail();
var username = email.slice(0,-9);
var ss = SpreadsheetApp.openById(username);
SpreadsheetApp.setActiveSpreadsheet(ss);
}
I suspect here your issue is a misunderstanding of the function '.openById()'.
This function is designed so that you identify and open the spreadsheet using a spreadsheet ID (The alphanumeric part of the URL when opening a sheet, such as "abc1234567"). From context and your use of the variable 'username', I think that instead you're somehow trying to open it based on an email ID (Such as user#domain.com).
Incidentally, you won't be able to open the sheet in an assigned tab using Scripts. That's not what it does, and it's unable to manipulate a users browser. Perhaps an extension for Chrome would be closer to what you're looking for.

how to import data from gmail to a spreadsheet using script

i was wondering if i can get the new emails data and put it in a spreadsheet .. the reason i'm making this is i need to track response time with custom search criteria like "FROM:(example#ie.com OR example#ie.com OR example#ie.com) ("done" OR "file") has:attachment".
and if the search have a new email i need to return it to a new row in the sheet within functions for the required ranges.
Here is a link that describe what i need to do
https://docs.google.com/spreadsheets/d/1oRrB8JSR1lVHGhjBd5-BU9XxkuaBZPG_MwVq5uEiioE/edit?usp=sharing
Appreciated
You can use GmailApp.search('Your_serach_criteria'). This will return an array of Gmail Threads which then you can iterate for messages and extract the required information and put in spreadsheet.

How to Call Google Apps Script from Web Page

Have searched high and low for this. I have a web page of basic HTML/CSS/JS. I want users to be able to visit the page and upon opening page, a call is made to a google script I made which takes information from a spreadsheet and displays some of it on the page. I am hoping I don't have to do any fancy set up like in Google's tutorials because none of them were helpful to me.
My Webpage ----> Google Script ----> Google Spreadsheet
My Webpage <---- Google Script <---- Google Spreadsheet
Users should be able to select an item shown on the webpage (item populated from spreadsheet) and click a button which will allow users to enter a new page with a URL derived from the selected item.
This is essentially a chat room program where the chat rooms are stored on a spreadsheet. I want users to be able to create a new chat room as well which should update the google spreadsheet.
Look into using the GET parameters. https://stackoverflow.com/a/14736926/2048063.
Here's a previous question on the topic.
You can access the parameters passed by GET in your doGet(e) function using e.parameter. If you call http://script.google......./exec?method=doSomething, then
function doGet(e) {
Logger.log(e.parameter.method);
}
doSomething will be written to the log, in this case.
Returning data from the script can be done using the ContentService, which allows you to serve JSON (I recommend). JSON is easiest (in my opinion) to make on the GAS end, as well as use on the client end.
The initial "populate list" call would look something like this. I will write it in jQuery because I feel that is very clean.
var SCRIPT_URL = "http://script.google.com/[....PUT YOUR SCRIPT URL HERE....]/exec";
$(document).ready(function() {
$.getJSON(SCRIPT_URL+"?callback=?",
{method:"populate_list"},
function (data) {
alert(JSON.stringify(data));
});
});
And the corresponding GAS that produces this.
function doGet(e) {
if (e.parameter.method=="populate_list") {
var v = {cat:true,dog:false,meow:[1,2,3,4,5,6,4]}; //could be any value that you want to return
return ContentService.createTextOutput(e.parameter.callback + "(" + JSON.stringify(v) + ")")
.setMimeType(ContentService.MimeType.JAVASCRIPT);
}
}
This method is called JSONP, and it is supported by jQuery. jQuery recognizes it when you put the ?callback=? after your URL. It wraps your output in a callback function, which allows that function to be run on your site with the data as an argument. In this case, the callback function is the one defined in the line that reads function (data) {.

Categories