google apps script - How to Split Form entries and replace text within a cell -
i have form serves application receive volunteer teams ngo. want create script sends email registrar upon completing form. that's easy part know how do.
i want include in "email notification" few key answers questions registrar see. know how accomplish.
here current code works:
function team_applicationmailer(e) { var recipient = "myemail@gmail.com"; var timestamp = e.values[0]; var name = e.values[3]; var country = e.values[1] var subject = e.values[1]+' wants volunteer!' ; var startdate = e.values[12]; var enddate = e.values[13] var hyperlink = "mylink.com" htmlbody = '<u><strong>'+name+'</u></strong> from: <u><strong>'+country+'</strong></u>just completed teams application form these dates: <u><strong>'+startdate+' '+enddate+'</u></strong><br><br>form completed on: <u><strong>'+timestamp+'</u></strong><br><br>view form: <a href="'+hyperlink+'">click here</a>'; mailapp.sendemail(recipient, subject, htmlbody, {htmlbody:htmlbody}); }
here's tricky part want add: want add together info found in e.values[19] , e.values[20], these values either multiple selection (e.values[19]) or checkbox (e.values[20]) , need values both simplified—i.e. text deleted—and perchance split when emailed.
the 2 questions identical. e.values[19] "what want do: 1st priority" multiple-choice options. , e.values[20] "what else want do" checkbox options. both questions have same 7 choices , each selection has long description (hence need shorten)
basically want e.values[19] value looks this:
optionx: (long description)
to in email:
what want do: optionx.
i don't want long description of alternative in "()" included.
for e.values[20] want values in email:
what else want do: optiona, optionb, optionc
instead of this:
optiona: (long description),optionb: (long description),optionc: (long description)
i've looked .replace , .split functions don't know how create them work together, checkbox option.
thanks help!
i wrote function this. removes within parentheses ()
. seems you're looking for.
var s = e.values[19]; s = s.replace(/\([^)]*\)/g,"");
if have parentheses within parentheses, allow me know, , have create quick edit.
so what's happening here.
it's looking(
. it's looking many characters can while matching )
@ end. without having )
inside. if had allowed )
inside, match optiona:
(...), optionb: (...), optionc: (...)
. want avoid this, not allow )
inside. that's [^)]
means. the g
flag means match "globally", or everywhere in string. google-apps-script google-spreadsheet
No comments:
Post a Comment