嵌入表单时获取表单提交的用户名 [英] Get username on form submission when form is embedded

查看:84
本文介绍了嵌入表单时获取表单提交的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在修改这里找到的帮助台教程脚本:



https://developers.google.com/apps-script/articles/helpdesk_tutorial



因为这是为了内部仅使用,我删除了联系人电子邮件字段,并将表单设置为用户名登录到电子表格。我已经编辑过formSubmitReply函数进行补偿:

原文:

 函数formSubmitReply(e){
var userEmail = e.values [3];
MailApp.sendEmail(userEmail,
Help Desk Ticket,
感谢您提交您的问题。\\\
\\\
我们将开始+
\\\\\\\\\\\\'\\\\\\\\\\\\''\\\\\\\\\\\\''\\\\\\\'

$ / code $ / pre
$ b $ p

  function formSubmitReply(e){
var userEmail = e.user;
MailApp.sendEmail(userEmail,
Help Desk Ticket,
感谢您提交您的问题。\\\
\\\
我们将开始+
\\\\\\\\\\\\'\\\\\\\\\\\\''\\\\\\\\\\\\''\\\\\\\'





$ b

正如你所看到的,我所做的只是改变userEmail变量被定义。当我查看Live Form并提交一张票据时,它似乎可行。



但是,在将表单嵌入到内部Google网站(我们的Intranet)后,它不再有效。



是否有一种方法需要在嵌入表单时定义userEmail?



我也试过这个:

  var userEmail = sheet.getRange(lastRow,getColIndexByName(Username))。getValue (); 

但是没有运气。任何帮助,将不胜感激!我很明显是新手,只是试图破解一些东西以使其正常工作。



干杯

解决方案

这个事件显然是以嵌入式的形式构造的。



试试:

  var userEmail = Session.getEffectiveUser()。getEmail(); 

这将独立于事件,并应识别运行脚本的用户。


I have been modifying the Help Desk tutorial script found here:

https://developers.google.com/apps-script/articles/helpdesk_tutorial

Since this is for internal use only, I removed the "Contact Email" field and set the form log the Username to the spreadsheet. I've edited the formSubmitReply function compensate:

Original:

function formSubmitReply(e) {
var userEmail = e.values[3];
MailApp.sendEmail(userEmail,
    "Help Desk Ticket",
    "Thanks for submitting your issue. \n\nWe'll start " +
    "working on it as soon as possible. \n\nHelp Desk",
    {name:"Help Desk"});
}​

Modified:

function formSubmitReply(e) {
var userEmail = e.user;
MailApp.sendEmail(userEmail,
    "Help Desk Ticket",
    "Thanks for submitting your issue. \n\nWe'll start " +
    "working on it as soon as possible. \n\nHelp Desk",
    {name:"Help Desk"});
}​

As you can see, all I've done is change how the userEmail variable is defined. When I view the Live Form and submit a ticket, it seems to work.

However, after I embedded the form into an internal Google site (our "intranet"), it no longer works.

Is there a way that I need to define userEmail to work when the form is embedded?

I also tried this:

var userEmail = sheet.getRange(lastRow, getColIndexByName("Username")).getValue();

But had no luck. Any help would be appreciated! I'm obviously new at this and just trying to hack a few things to get it working properly.

Cheers

解决方案

The event is apparently being constructed differently for the embedded form.

Try:

var userEmail = Session.getEffectiveUser().getEmail();

That will be independent of the event, and should identify the user running the script.

这篇关于嵌入表单时获取表单提交的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆