Can someone please tell me where I'm going wrong?!

43 views
Skip to first unread message

Adriana Lamb

unread,
May 12, 2023, 10:45:55 AM5/12/23
to Google Apps Script Community
Backstory: I work at a company with a large fleet of heavy-duty trucks. Of course, when something breaks on one we would need one of our mechanics to look at it, so I created a Google Form for the drivers to request the repair.

I recently learned that I could use App Scripts to make the responses from the Google Form self populate onto a Google Doc template for a service order and I used a tutorial online to create the code. It went almost perfectly but there is ONE stinkin' box that won't autofill no matter what I try. My amateur skills are quite lackluster but I'm hoping my mistake will be glaringly obvious to someone here!

The piece I'm having trouble with is "Unit Number"

I have attached a screenshot of my code. 
I also have screenshots of the auto-filled Google Doc where that damn box won't autofill, the column headers on the Google Sheet, and the question from the Google Form that I will attempt to add in the comments (I'm new here lol).

Please tell me the error of my ways!! TIA!!
the code.png

Adriana Lamb

unread,
May 12, 2023, 10:46:21 AM5/12/23
to Google Apps Script Community
populated google doc.jpg

Adriana Lamb

unread,
May 12, 2023, 10:46:51 AM5/12/23
to Google Apps Script Community
question on form.png

Adriana Lamb

unread,
May 12, 2023, 10:47:11 AM5/12/23
to Google Apps Script Community
headers on google sheet.png

Bennett, Scott

unread,
May 12, 2023, 11:11:49 AM5/12/23
to google-apps-sc...@googlegroups.com
Just looking quickly here.  But your code is looking for "unitNumber" but you just have "unit" in the document.

--
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/32a7817c-8ea4-4448-a597-49f4af7a216an%40googlegroups.com.


--
Scott Bennett


Adriana Lamb

unread,
May 12, 2023, 11:26:26 AM5/12/23
to Google Apps Script Community
Whoops sorry, I attached the wrong screenshot! That was from one of the earlier variations I tried...  "unit", "unit #", and "unitNumber" were all tried and not a single one worked!

The correct/newest screenshot is below

CORRECTED populated document.jpg

Nahum Sanchez Arce

unread,
May 12, 2023, 11:30:41 AM5/12/23
to google-apps-sc...@googlegroups.com
Thank you very much, it will help me in my transmission from html to appscript form

--
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.

CBMServices Web

unread,
May 12, 2023, 1:40:12 PM5/12/23
to google-apps-sc...@googlegroups.com
Your template says {{Unit}} but your code is looking for {{unitNumber}}.

Change one or the other for them to match.


--

Adriana Lamb

unread,
May 12, 2023, 1:43:12 PM5/12/23
to Google Apps Script Community
Yeah sorry about that, I attached the wrong screenshot! That was from one of the earlier variations I tried...  "unit", "unit #", and "unitNumber" were all tried and not a single one worked!

The correct/newest screenshot is below

CORRECTED populated document.jpg

CBMServices Web

unread,
May 12, 2023, 1:47:23 PM5/12/23
to google-apps-sc...@googlegroups.com
Add this statement in your code just above where you do replacement.
 Logger.log("Unit:" + unitNumber);

If this prints valid value for unit Number, it could be it is getting confused by the fact it is a number and not text.

Add this one line above the replace:

unitNumber = String(unitNumber);

Good luck.

Reply all
Reply to author
Forward
0 new messages