Trying to write App Script for sheets/forms to automate email response - forms

I have a form and sheet but I'm not sure which is better to use to pull data from or create the trigger of form submit.
I am trying to create an email response to a form that is based on a google doc with images and text and will pull the name and responses from the form (or sheet).
Here are the work files. I will need to add this script to a different form/sheet later.
https://drive.google.com/drive/folders/1MhHOPjMD0JwVgP98majrKBPk-Cf1_Uwn?usp=sharing

There is actually an existing template for something related to what you are asking for in this Google developer documentation https://developers.google.com/apps-script/samples/automations/content-signup where you can easily make a copy of the file and change the values based on what you need.
This is basically allowing you to send emails from a trigger "onFormSubmit" based on what people filled in the Google form. Please let me know if you actually need the full code though! Or what exactly you are trying to achieve if the template is not working for you.

Related

Elementor: Custom Query that uses a pre-set target ID

So, I am trying to set the target ID for an elementor template using a short code ... e.g. can I use a shortcode like: [elementor-template id="15639" postid="9999"]?
Here my intention is to reuse an elementor template which pulls the data from post #9999 into the template. The next one might be #10078, etc. Is this possible? I can't seem to find the answer or I am searching for the wrong terms. Thx much! --Dano
P.S. The elementor template I created uses a Modal Widget, so the user can click a thumbnail (from post #9999) and then get an enlarged image (diagram) + all the data regarding the diagram (using ACF). To be clear, I am using a single post template type, NOT an archive. I don't want to create many elementor templates. I want one template that reuses the post data from a preset ID. Of course, the current page or post (that the user is on) is not the target ID I need, thus my question ... Maybe I need a custom query that will allow me to set a target ID in the shortcode?
Thx in advance!

Is there a way to create an output form based on Google Sheets data?

What I want to make
Is this possible?
I'd like to create an output form that reads data from a Google Sheets spreadsheet. In the form, users would enter a few values (entering their name and some ID number, for example) and view the corresponding information in the connected spreadsheet but not any other information in the sheet. Something like an output form in Microsoft Access. I'm hoping there's a way to accomplish this in Google Sheets using existing tools and maybe some scripting.
More generally, though, any way to create this type of 'limited visibility' on a per-user basis for Google Sheets data would be useful. (The 'protect sheet' function in the menu doesn't accomplish this; see below.)
For reference, my specific use case at the moment is as a teacher and wanting a way for students to see specific information related to them from my student information spreadsheet but while not revealing other students' information. I would have a simple form where they enter a name and maybe some personalized code that I give them so they can see their attendance record or something else. For my purposes, I don't need the form to be extremely secure as none of the information is all that sensitive (although more secure is better), but I don't want to be just putting all the information there in front of them by giving them access to the entire sheet.
What I've tried so far
I made a new spreadsheet file with two sheets; one sheet was visible to function as a form, and the second sheet was not visible (which I accomplished via the 'protect' menu option). I used importrange() to read in the relevant data from my primary spreadsheet to the new spreadsheet's non-visible sheet. On the visible sheet, students entered their name from a drop-down and entered their student ID as validation. If the student's name and ID matched, the first sheet did a vlookup() to read in information from the protected sheet and some information from their student record.
Here's what I made, in case my description doesn't make sense: https://drive.google.com/open?id=1cHO2jzMh1mkXvlLh-M4eYqN7v11t95-GnfWqL5IwQ14&authuser=0
This had two problems, one small and one big.
The small problem was that every student could see the "form" sheet at the same time. If two students opened the spreadsheet at the same time they would see any information that the other student had entered. I handled this by writing a simple script to automatically reset the "form's" input cells after 20 seconds. Also, any time the form was opened by a new person, the "form's" output cells were erased. So, obviously not a brilliant solution, but for my purposes, this was mostly good enough.
The big problem was that Google's own preview viewer (built into Google Drive and the like) ignores protected ranges and sheets and displays the entire contents a spreadsheet. (Normally, protected sheets are not visible at all and don't appear in the list of sheets at the bottom of the screen unless the viewer has access to them.)
In my case this meant included the protected one that shouldn't have been visible at all, rendered as if it were a print preview, meaning the students were actually able to view all of the other students' data in one big table.
Are you familiar with Web Apps?
An Apps Script Web App allows you among others to output selected Google Document contents into a browser.
Hereby, you can use the method Session.getActiveUser() to obtain the email of the user and dynamically adjust the data the user is going to obtain in function of his email (BTW, you can also use Session.getActiveUser() in the spreadsheet, to detect the user automatically instead of asking him for his name).
Simple example workflow:
Replace in column A student names through student emails (the Gmail addresses with which the users authenticate their sessions and access Google Sheets)
Bind to the spreadsheet a script with a content similar to the following:
function doGet(){
var ss=SpreadsheetApp.getActive().getSheetByName('Data');
var range=ss.getDataRange();
var values=range.getValues();
var user=Session.getActiveUser();
var output="";
for(var i=1;i<ss.getLastRow();i++){
if(values[i][0]==user){
for(var j=1;j<ss.getLastColumn();j++){
output+=(values[i][j])+" ";
}
}
}
return ContentService.createTextOutput(JSON.stringify(output));
}
Make sure that you have a doGet() function and a return statement.
After running the script once manually to trigger authorization flow, deploy it as a Web App - executing it as User accessing the web app and giving access to Anyone (unless desired otherwise).
Copy the URL of your WebApp and forward it to your student.
When the student open the URL in their browser - they will obtain their results - provided their email is listed in the sheet.
Please note that the code provided is a simple sample, that retrieves
all data and outputs it as a string. Feel free to modify the script
e.g. retrieving only columns of interest and outputting the data as a
html table, rather than a simple string.

Dynamic CRM - insert external hyperlink with dynamic parameters in Email workflow

I have a Workflow in CRM 2016 on premise that sends an email to a customer when an order is created. The email contains a URL link to external website used for scheduling. The problem is that the hyperlink in the email doesn't fill the parameters we are using from the CRM entities.
I tried several ways to do this. the first way was using the Insert Hyperlink when creating the email through the workflow. this creates the following tags:
<hyperlink><name>Pro Services Online Scheduling Portal</name><value>https://secure.website.com/ProServices?name={Ship To Contact(Order (Order))}&email={Email(Ship To Account (Account))}&OrderID={Order ID(Order (Order))}&Company={Customer(Order (Order))}&skip=0</value></hyperlink>
This correctly adds the hyperlink into the email but the actual link looks exactly as it does in value tag without the CRM values.
I tried just adding the link as plain text like so:
https://secure.website.com/ProServices?name={Ship To Contact(Order (Order))}&email={Email(Ship To Account (Account))}&OrderID={Order ID(Order (Order))}&Company={Customer(Order (Order))}&skip=0
This displays the correct URL with the correct CRM values like: https://secure.website.com/ProServices?name=JonDoe&email=jdoe#email.com&OrderID=ORD-123456&Company=FakeCompany&skip=0
However, the URL itself is still missing the values so if the customer clicks on the link, the incorrect parameters will be sent. It does work if the customer were to copy and paste the link text instead of clicking the URL but most customers would rather click the link.
I even tried used an HTML anchor tag but that also didnt work.
Has anyone else encountered this problem?
Any help would be appreciated.
Here's some blog posts that helped but still looking for answers.
http://dotnetskills-reenapatel.blogspot.com/2014/02/how-to-form-dynamic-hyperlink-url-for.html
http://www.magnetismsolutions.com/blog/paulnieuwelaar/2012/06/25/dynamic_clickable_email_hyperlink_dynamics_crm_2011_workflow
If you want to use hyperlink then you have to do something similiar to what CRM does for field Record URL(Dynamic).
You can create a new field on the entity say 'EntityName Hyperlink'. Then use plugins to set this value to the desired link on create event.
You can then use this field to create your hyperlink. We do something similair for our case entity we have field Case Hyperlink which i set on create event.
Then we insert it on outgoing emails like this
<hyperlink><name>Hyperlink</name><value>{Case Hyperlink(Case)}</value></hyperlink>
We ended up creating a custom workflow activity to add the hyperlink using SparkleXRM

Is there a way to embed an iframe in an email with text that updates?

I want to embed an iframe inside an email that contains the 10 most recent chat messages. Is there a way to make this iframe dynamic so that it always shows the latest 10 chats regardless of when the email is opened? If the iframe is not the correct way to do this, is there a better way?
You can implement an iframe into the email - but your mail will be recognized as spam by many providers.
You should try to render your content dynamically into an image and implement that image into the email.
There kind of is a solution. It is using Dynamic CSS with a fallback of a Dynamic image to pull the information. It is not elegant really as for some clients (e.g. Outlook) this is not available at all and will only display initial information. It also utilizes a link for a style sheet which also severely limits which clients this will work in.
The fall back dynamic image is a bit more comprehensive in client support, but much harder to maintain as you will need to build something that programatically pulls the tweets (HTML webpage potentially) and then also have something that creates and hosts an image for the email to pull. This is not a short, simple thing to set up and may not be worth the required back end work for a simple email.
See this link for a bit more in-depth info on how this can be done for adding a live twitter feed into an email: https://litmus.com/blog/how-to-code-a-live-dynamic-twitter-feed-in-html-email
Since there was no accepted answer i thought i would give my input as well.
Litmus had done something similar for their live twitter feed in emails sometime ago.
The method i can think off is to create a PHP page which takes 10 images and makes it into 1. PHP can have a loop that checks for increments from a specific number and if it exists then add to that 1 image. When there is a new chat image added, PHP will disregard the last one and add the new in the loop.
For anyone reading this in 2022, this is possible with AMP.
Instead of an iframe, you can create a dynamic email easily.
check out amp.dev
Note: AMP is not supported by many email clients

How to update the responses of the google form to the form itself

I am creating a Google Form. I want to insert a count in the end(anywhere,not specific) of the form which will show the number of responses submit till date.This goes like updating the live count. I have tried using script editor for Google Form Add-ons option.But I am unable to view the results automatically or changes. It asks me to accept "Terms of Service" which I don't want to do right now because I am not sure about the way it may result.
There are various options available to view the form results/responses.But here I don't want to view the results later.They should get updated when we click the submit button on form.Please note..simultaneously many users may fill the form.
To implement this,I have thought of logic like whenever submit button gets clicked..the text in the form should get updated.
Please suggest how I can add the count or apply above logic of whenever submit operation is performed. Is it possible?? Any other suggestions are welcomed..Thanks in Advance!!!
I found another possible way of doing this..I received all the responses in Google Spreadsheet..which I later embedded in my site. Solves the purpose..And the embedded data gets updated automatically for the responses !! Cheers