Approval process through mail with a button

1,584 views
Skip to first unread message

Dora Samy

unread,
Sep 15, 2021, 4:15:04 PM9/15/21
to Google Apps Script Community
Hi,
I want to know whether it is possible using appscript to create a work flow using
buttons in email template to approve and automatic updation in gsheet?
is it possible something like this?

cbmserv...@gmail.com

unread,
Sep 15, 2021, 5:00:08 PM9/15/21
to google-apps-sc...@googlegroups.com

Yes, that is possible. You would have to create some webapps to handle the button responses, but it is quite doable and I have done that in the past.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/850a4dfd-e877-4df4-9ba8-ce3fe77bd9a8n%40googlegroups.com.

Dora Samy

unread,
Sep 17, 2021, 3:28:48 AM9/17/21
to google-apps-sc...@googlegroups.com
How should be it like,
Providing the webapp link in mail for the user to click d webapp and click the approval button.

I have one doubt . Can we create a button in mail html template and make it to do something?
Is it something doable?



You received this message because you are subscribed to a topic in the Google Groups "Google Apps Script Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-script-community/zMGzlfoCP2I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/004601d7aa74%24a8f7a850%24fae6f8f0%24%40gmail.com.

cbmserv...@gmail.com

unread,
Sep 17, 2021, 3:30:07 PM9/17/21
to google-apps-sc...@googlegroups.com

Dora,

 

Here is how I have done it in the past:

 

Here is a script that generates the email with the buttons:

 

function generateApproveButtonEmailContent()

{

  var msgBody = "";

  const orgName = "Someone";

  const approvalWebApp = https://.../;  // insert your web app exec address

  const approveButton = https://dl.dropboxusercontent.com/s/..../Approve.png?dl=0;  // this is approve button picture

  const declineButton = https://dl.dropboxusercontent.com/s/.../Decline.png?dl=0;  // this is decline button picture

 

  var approveURL = approvalWebApp + "&Approval=Approved"

  var declineURL = approvalWebApp + "&Approval=Declined";

  

  msgBody += "<p>This message is for: " + orgName",</p>";

  msgBody += "<p>We have a new request available for you.</p>";

  msgBody += "<p>To approve this email request click approve button.</p>";

  msgBody += "<p align=center style='text-align:center'><span><a href=" + approveURL;

  msgBody += "><span><img border=0 width=195 height=60 id=Img1 src=" + approveButton + "></span></a></span></p>";

  msgBody += '</div>';

 

  msgBody += "<p>To decline this email request click decline button.</p>";

  msgBody += "<p align=center style='text-align:center'><span><a href=" + declineURL;

  msgBody += "><span><img border=0 width=195 height=60 id=Img2 src=" + declineButton + "></span></a></span></p>";

   

  return msgBody;

 

};

 

To use something like this you would need to do the following:

 

  1. Create a webapp that expects at least one parameter. In this case called Approval and the value expected is either Approved or Declined. You can pass other data if needed for your application.
  2. You need a cloud saved picture for the Approve button and one for the Decline button. I use dropbox in my example because I could never figure out how to add a google image inside an email (Perhaps someone in this forum can tell us how to do that.
  3. Email content above presents two buttons that call the same webapp but with different parameter setting for each. (either approve or decline) depending on which button the recipient of the email clicks.
  4. The email needs to be sent as an HTML content of course for the correct formatting.

 

Hope this helps.

 

George

Message has been deleted

cbmserv...@gmail.com

unread,
Sep 20, 2021, 1:53:18 PM9/20/21
to google-apps-sc...@googlegroups.com

Hi Dora,

 

Glad you found it useful. Yes, you can pass other parameters in the same click. But you will need to make sure that the emails are going to the right individual also be careful of not using any private information in the parameters. If for example employee id is a private info at your company, consider using a request ID instead which can be mapped in your software back to the correct employee.

 

To add parameters to the webapp call, you just need to string them in to the end of the URL as follows:

 

https//webappurl?parm1=x&parm2=y&parm3=z etc..

 

Then in your webapp doGet code, you look up the parameter for what is passed in.

 

For the PDF, I do not know of a way to have the header in each page within the standard google pdf converter code. You can do your own pdf conversion code which would not be ideal as you would need to do page by page to ensure headers are in and convert the spreadsheet info into HTML then back to PDF to make it work. Perhaps someone else here might suggest an alternative.

 

 

From: google-apps-sc...@googlegroups.com <google-apps-sc...@googlegroups.com> On Behalf Of Dora Samy
Sent: September 19, 2021 1:50 PM
To: Google Apps Script Community <google-apps-sc...@googlegroups.com>
Subject: Re: [Apps-Script] Approval process through mail with a button

 

Hi George,

Thank you very much.

Till now i didn't know exactly how  that button type is done in mail.

This helps me in a great way.

I use google drawings for inserting image and publishing it and use the pic for buttons, even though look is not great, i kind of manage.  

I have one doubt. i have existing web app for  staff to select the forms for getting calculation  or  fill the form for leave request. Same i use hide , unhide scenarios.

In this case, i have created a separate web app and as per your above function i incorporated the parameter and linked the web app in the mail template.

My doubt is it is possible to get the parameter of the existing webapp to the one created for approval or rejection.

ie.

emp id is 12345, when the staff enters in the original webapp his emp id , leave date and press request button, the mail goes for approval with a pdf leave predefined file only adding date

and emp id in that.

 

Now what i want is when the approval is made, it should be into the sheets with the emp id and approval. so is it possible to update the approval webapp with emp id parameter automatically like how we do in native google forms by concatenating id in the form when it is sent to the user?

is it possible?

 

And also one more doubt. do you have any idea of how to repeat headers in google sheets for export to pdf function.

Even after i set fzr parameter to true, the headers are not repeating.

i have a multi page pdf which is taken from sheet of dynamic items and quantities which i need add and delete rows in sheet. so it is having a chance of going into more than 1 page.

hence i want a header and footer to be set in pdf function.

i tried few options apart from using doc, but it is not yielding me results. Have you done something like this, is there any workaround possible?

Message has been deleted

CBMServices Web

unread,
Oct 7, 2021, 1:23:56 PM10/7/21
to google-apps-sc...@googlegroups.com
Hi Dora,

If you are running the webapp as yourself, you can only send emails from your own account and not from them.

What you can do is set the reply-to address to theirs so that any reply would go back to them instead.

You can also set the sender name I believe to make it look like it came from them. Check into the GmailApp.sendEmail options to see what you can change. But emails sent will be done via your admin account and not from theirs.

Alan's suggestion is correct that you can have a webapp be run as the user and that would cause the emails to be sent by them, but doing so would require each user to have to authorize the script first. Depending on how many users you have, this could be a messy solution.

If you want to go in that direction, you would need 2 webapps. One that the user runs and the other which is run as your account so that you have access to the spreadsheets and documents you need to generate the email content.

The user webapp would be the front end. It should do following:
- get email address of user
- get relevant data for generating request
- call backend webapp to generate email content
- with emailcontent received back, send email on behalf of user.

The backend webapp would do following:
- receive web call with relevant parameters
- lookup spreadsheet or docs for relevant information
- return content of email to be sent back to caller of webapp.

Hope that helps.

George 

On Thu., Oct. 7, 2021, 5:20 a.m. Dora Samy, <dorasa...@gmail.com> wrote:
Hi George,
Thanks it helped me in immense way.
I have one doubt with respect to the same.. Here i am publishing the web app as for within domain users under the admin.
but i need the mail has to be sent by employee mail or atleast dept head mail..

What i did is, i created a sheet and based on d users i had alternated between sheet for mail -ie the data will pop into that and on edit mail will be sent from user mail.
But that is failing at times.
When i posted asked here about that, Alan had given me the idea regarding post load between admin and user web app by creating a separate web app for user publishing, so as to send mail. But i am not able to understand how exactly to call the email function in that. should i reference it in do post in the user web app.

Do you have done something like this? any idea you can give me with respect to this..

Dora Samy

unread,
Oct 16, 2021, 8:37:48 PM10/16/21
to Google Apps Script Community
Hi George,
In that case how the two webapps can be connected. is it as a post request ?

CBMServices Web

unread,
Oct 17, 2021, 12:09:30 AM10/17/21
to google-apps-sc...@googlegroups.com
Correct. One webapp will post a request to the second one using URLFetch to do so.

Dora Samy

unread,
Oct 17, 2021, 12:04:50 PM10/17/21
to Google Apps Script Community
yes will try that.. for post request cookies must be considered in payload like normal web page login payload?

and one more thing, i came across a sheet, where  certain menus are disabled like edit, insert etc.
There was no script as such.I checked in script editor, it is blank and these menus are disabled after i made a copy, even copying the tab is disabled.

few buttons along with charts were on the sheet tab.

How it could have been done like that? i am attaching screenshot of that.  For learning purpose, i am curious to know how this has been done..
doubt.png

CBMServices Web

unread,
Oct 17, 2021, 1:46:58 PM10/17/21
to google-apps-sc...@googlegroups.com
This happens when the spreadsheet was shared with you as view only and not as editor. This disabled the various menu items which would have permitted you to modify. You can also set security settings to prevent anyone from downloading or copying the spreadsheet if only given view permissions.

Dora Samy

unread,
Nov 6, 2021, 8:45:25 AM11/6/21
to Google Apps Script Community
Hi George,
How this can be done. I only see accessibility settings and spreadsheet settings. is it done in script editor?
in this case even after make a copy, we cannot see the whole sheet? is it so?
Like this can we protect script editor functions from accessing also?

CBMServices Web

unread,
Nov 6, 2021, 12:33:23 PM11/6/21
to google-apps-sc...@googlegroups.com
I was recently looking at one of my less used Gmail accounts and saw the same thing as you. In my case I was owner and editor of the spreadsheet so I should have access to the Edit Script command.

I saw that the actual command was no longer under the Tools menu but moved over by 1 menu set to the right. I think it was called something like Extend or whatever. Not sure why Google moved it but it may be due to a change that they are rolling out but has not made it yet to all users.

So check out the menu set to the right of the Tools menu set.

Dora Samy

unread,
Mar 26, 2022, 8:38:15 AM3/26/22
to Google Apps Script Community
Hi George,
One clarification, incase of issue in publishing internal add on under store listing. whom should be contacted. i recently had issue by getting error make sure everything is correct when i try to publish it in store listing? is there google support for this?

Dorabajji

unread,
Jun 21, 2022, 12:52:26 PM6/21/22
to Google Apps Script Community
Hi George,
One doubt with respect to cardservice.
I am trying to set onchange for textinput. 
i am not able to change the value rather i had to use navigation to show updated card.
is there possibility to update textinput field without updating card?

CBMServices Web

unread,
Jun 21, 2022, 1:55:45 PM6/21/22
to google-apps-sc...@googlegroups.com
I have not used Cardservice yet. Perhaps others here can answer your question.



Reply all
Reply to author
Forward
0 new messages