appmaker - creating a link to the record in a completed form -
i pretty new app maker. have form user completes called creditapplication (it's linked datasource called creditapplication).
form has submit button. upon submission, want email link record completed emailed user.
i having trouble creating link. link bring emailed user same record in creditapplication form. have listed have below.
the creditapplication form has submit button onclick set to:
createrequest(widget).
the creditapplication datasource has following code in oncreate event:
var = "jdoe@gmail.com"; var subject = "new online credit application submission - " + record.firstname + " (sales contact: " + record.salescontact + ")"; var msg = "a credit application has been submitted " + record.firstname + "." + "<br><br>"; var appurl = scriptapp.getservice().geturl() + '#creditapplication?requestid=' + record._key; msg = msg + appurl; mailapp.sendemail(to, subject, msg, {htmlbody: msg});
my client javascript code in library called clientscripts , displayed below:
/** * replaces url history state reflect changes upon navigation * different screen. * @param {string} requestid - id of selected request. */ function replaceurlforreadrequest(requestid) { var params = { requestid: requestid }; google.script.history.replace(null, params, app.pages.newpage1.name); } /** * replaces url history state reflect changes upon navigation * different screen. * @param {page} page - application page navigate. */ function replaceurlforpage(page) { var params = {}; google.script.history.replace(null, params, page.name); } /** * creates new request , redirects user read screen afterwards. * @param {widget} submitbutton - button triggers action. */ function createrequest(submitbutton) { if (!submitbutton.root.validate()) { return; } var newpage1 = app.pages.newpage1; submitbutton.datasource.createitem(function(record) { if (app.currentpage === newpage1) { replaceurlforreadrequest(record._key); } }); app.showpage(newpage1); replaceurlforpage(newpage1); }
you can add url parameter identifies record before emailing url. when users retrieve page, use parameter adjust query filter load record.
url parameters can added url client script:
/** * adds url parameter. * @param {string} name - name of url parameter; * @param {string} value - value of url parameter; */ function addurlparameter(name, value) { google.script.url.getlocation(function(location) { var params = location.parameter; if (params[name]) { console.log('url parameter exists'); } else { console.log('adding url parameter'); params[name] = value; google.script.history.replace({}, params); } }); }
here example of onattach event handler. "project" name of datasource. uses built-in data field "key" set query filter.
/** * loads record based on "key" parameter in url. */ function loadpagebykey() { google.script.url.getlocation(function(location) { if ('key' in location.parameter) { var datasource = app.datasources.project; datasource.query.clearfilters(); datasource.query.filters.key._equals = location.parameter.key; datasource.load(function() { datasource.query.clearfilters(); }); } }); }
Comments
Post a Comment