You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Forms脚本中如何从e.namedValues获取特定字段的值?

Google Forms脚本中如何从e.namedValues获取特定字段的值?

Hey there! Let's work through why your code isn't grabbing the "notificar" field value correctly—this is a super common quirk with Google Forms triggers, so I’ve got a few troubleshooting steps for you:

  • First, double-check the exact field name match
    Google Forms uses the exact display text of your question as the key in e.namedValues, including capitalization, spaces, and even special characters. For example, if your form question is actually "Notificar" (capital N) or "notificar " (with a trailing space), your hardcoded "notificar" won’t line up. The easiest way to confirm is to log all the keys being passed in:

    const datos = e.namedValues || {};
    console.log("All form fields received:", Object.keys(datos));
    

    Run a test submission, then check your script logs—this will show you the precise key name Google is sending, and you can adjust your code to match it exactly.

  • Simplify your value retrieval code
    You don’t need to use Object.keys().find() here; you can directly access the field if you know the correct key. Once you’ve confirmed the right key name, you can simplify your code to:

    const datos = e.namedValues || {};
    const correoDestino = datos["notificar"] ? datos["notificar"][0] : "";
    console.log("Recipient email:", correoDestino);
    

    Remember, every value in e.namedValues is an array (even for single-line text fields) because some question types (like checkboxes) return multiple answers—so using [0] to get the first entry is correct for most single-input fields.

  • Verify your trigger type
    Make sure you’re using an "On form submit" trigger for your function. If you accidentally set up a time-driven trigger or another type, the e object won’t have the namedValues property at all. You can check this in your script editor under Edit > Current project’s triggers—confirm the trigger is linked to your submission handler and set to fire on form submit.

  • Check if the field was actually submitted
    If your form uses section navigation or conditional logic, it’s possible the "notificar" question wasn’t visible to the user when they submitted. For example, if the question only appears based on a previous answer that wasn’t selected, Google won’t include it in e.namedValues. Test submitting the form while ensuring the "notificar" field is filled out every time to rule this out.

9 times out of 10, the issue is just a tiny mismatch in the field name—logging all the keys will immediately show you where the problem is. Give these steps a try, and you should be able to grab that email address without issues!

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.08 11:30:28