The following code is used to send an email to the respondent of a google form. The onsubmit call is from the spreadsheet that stores the responses.
I am not sure how to get the forms ID to use the solution given in several other places. Basically I just need to know how to call the getRespondentEmail(). I've tried calling it using FormApp.getActive() but I read that only works when you are working in the form it's self.
If you want to offer a solution that requires using the form ID, an explanation of how to get the ID would be great.
var GetUserEmail = getRespondentEmail().
var subject = "Skiver Production Report Successfully Submitted";
var textbody = "You have successfully submitted a Skiver Production Report. Do not reply to this email as it is not monitored.";
var message = "You have succesfully submitted a Skiver Production Report. Do not reply to this email as it is unmoinitored." ;
var cc = "techlab#worldwidefoam.com";
var sendername = "Quality Function";
GmailApp.sendEmail("bob#notArealemail.com", subject, textbody, {
cc: cc,
name: sendername,
htmlBody: message
});
To get the id of an element you can simply use the document.getElementById(arg) method. For example:
var myForm = document.getElementById("ID");
For simply calling getRespondentEmail you just place getRespondentEmail() in your code. Your first line is doing this correctly but the . at the end needs to be removed or replaced with a ;, which is likely causing your error:
var GetUserEmail = getRespondentEmail(); // replace . with ;
Lastly if you would like to use getRespondentEmail() anywhere make sure it is in a global scope. Meaning it's not defined in any functions or closures.
Related
I created a button in an account form entity by ribbon workbench and then I tried to create a javascript code. When executed the code is just fetching the account id and showing that id in the alert and then I registered that file to that button by ribbon workbench action command.
I wrote the below code, please let me know what is wrong with that.
I am expecting an alert box with that id, but nothing is happening
The code is below:
fetch = {
fetchingacountid: function(executionContext){
var formContext = Xrm.Page.context.getFormContext();
var accountId = formContext.data.entity.getId();
alert("The ID of the current account is: " + accountId);
}
}
Possibly you might have missed to add the PrimaryControl CRM parameter in ribbon command. Then you don’t need Xrm.Page, instead you will get the context directly in the first parameter executionContext. Read more
I'm having a really hard time sending an automated email (with Google Apps Script) that includes a URL that contains query parameter.
Expected Behavior
Google Apps Script (specifically, the Gmail service) sends an email, and part of the email body contains a URL with a query parameter. The URL will look something like this:
http://my.app/products?id=Bz9n7PJLg8hufTj11gMF
Observed Behavior
The Gmail service seems to be stripping out the = from my URL. So, the body of the email ends up looking like this:
...
http://my.app/products?idBz9n7PJLg8hufTj11gMF
...
Obviously, that link won't work.
I've checked other questions here on SO, and I've tried working with the base encoding tools from the GAS Utilities service, as well as working with the encodeURI() JavaScript method. No luck so far.
Email-sending Code
//////// GENERATING MESSAGE FROM ID ////////////
// Gets message from ID
var id = Gmail.Users.Drafts.get('me', 'r-1006091711303067868').message.id
var message = GmailApp.getMessageById(id)
var template = message.getRawContent()
// Replaces template variables with custom ones for the user using RegExes
let listingUrl = 'http://my.app/products?id=xyz'
let creatorEmail = 'hello#gmail.com'
let creatorUsername = 'Sam'
template = template.replace(/templates#my.app/g, creatorEmail)
template = template.replace(/firstName/g, creatorUsername)
//** Below is the string that gets modified and broken **//
template = template.replace(/listingUrl/g, listingUrl)
// Creates the new message
var message = Gmail.newMessage()
var encodedMsg = Utilities.base64EncodeWebSafe(template)
message.raw = encodedMsg
// Sends it
Gmail.Users.Messages.send(message, "me", Utilities.newBlob(template, "message/rfc822"))
Regex-based Solution
With the help of Tanaike and Rafa Guillermo, the solution that ended up working for me was to replace = with = by using a little .replace() like this:
listingUrl = listingUrl.replace(/=/, '=')
On my website I'm trying to make a modal that informs the user of their username (generated from their forename and surname) and informs the users that they have been added to a moderation que for their account to be approved. I create the account within a php file called with ajax and then use JSON to feedback a integer that informs the javascript if the process was successful and if so what the user's username is. My modal opens fine if the account was created and the information is displayed about the approval process, however I cannot seems to get it to display the section with the username in. Can you try and see where I'm going wrong.
Javascript
var RegisterSuccess = new Array();
var RegisterSuccess = JSON.parse(Feedback);
if (RegisterSuccess[0] == 0){
$('#mdlInfo').html('<p>Your account has been created under the username: "<strong><span id="spnUsername"></span></strong>". You <strong>must</strong> remember this as you will require it to login to your account.</p>');
$('#mdlInfo').html('<p>Your account has also been added to a moderation que. You must wait until a member of staff activates your account!</p>');
$('#spnUsername').html(RegisterSuccess[1]);
$("#mdlRegister").modal("show");
PHP Output code
$Feedback = json_encode(array($RegisterSuccess, $username));
echo $Feedback;
Thanks in advance!
Why don't you just return a proper json_encoded array from PHP? No need to assign a variable, just do
echo json_encode(["success"=>"true","username"=>"$username"]);
and in the javascript (no need to assign the RegisterSuccess as array either), just do
var returnValue = JSON.parse(Feedback);
(you should avoid calling the variable RegisterSuccess - chose a neutral name so you can use it for both success and error without issues. Then just do
$('#mdlInfo').html('<p>Your account has been created under the username: <strong><span id="spnUsername">'+returnValue['username']+'</span></strong>. You <strong>must</strong> remember this as you will require it to login to your account.</p><p>Your account has also been added to a moderation que. You must wait until a member of staff activates your account!</p>');
$("#mdlRegister").modal("show");
I am trying to have the google forms on our website auto-notify us when a user completes the form and then return the data that they entered in a concise email. I do not like the way google notifies you it simply links to you the form to view the response. I searched online and found this code:
function sendFormByEmailPrayer(e)
{
// Remember to replace XYZ with your own email address
var email = "admin#communionchapelefca.org";
// Optional but change the following variable
// to have a custom subject for Google Docs emails
var subject = "Prayer Form Form Submitted";
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var urlToDoc = SpreadsheetApp.getActive().getUrl();
var body = "";
body = body + "Link to Document: " + urlToDoc;
var message = body + "\n\n" + "";
// Credit to Henrique Abreu for fixing the sort order
for(var i in headers)
message += headers[i] + ' = '+ e.namedValues[headers[i]].toString() + "\n\n";
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp here.
MailApp.sendEmail(email, subject, message);
// Watch the following video for details
// http://youtu.be/z6klwUxRwQI
// By Amit Agarwal - www.labnol.org
}
On Form Submit screenshot:
It works great on my one form, but when I copied and pasted this working code to our other 6 forms, it does not work at all. How do I get this to work across our 7 forms? Thanks in advance.
Well I found a better solution than the code presented above. If you use the new Google Forms you can add an "add-on" (YourForm-->Three Dots in top right-->Add-ons).
From there look for "Simply Send" it will auto email a response with headers. Took me about 5 seconds to setup each of my forms.
I'm getting "TypeError record.viewCurrentLineItemSubrecord is not a function" when trying the below code:
function saveRecord(){
var isChild = nlapiGetFieldValue('parent'); //will be null if parent record
if(!isChild){
var record = nlapiLoadRecord('customer', 177986, {recordmode: 'dynamic'});
record.selectLineItem('addressbook', 1);
var subrecord = record.viewCurrentLineItemSubrecord('addressbook', 'addressbookaddress');
var address = subrecord.getFieldValue('addr1');
nlapiLogExecution('DEBUG', 'Single Record Test', 'Child Record Address: ' + address);
}
return true;
}
Ultimately, I'm trying to update the billing address of all child records when the parent record is saved, hence the above "saveRecord" function. Before I get too complicated, I wanted to try the code from "Sample Scripts for Address Subrecords" page in the Help Center. My code is nearly identical to the Help Center's code, so why isn't it working? What am I missing?
Unfortunately, it doesn't works on client scripts.
One possible solution is write a suitelet (if you want to stick with client script, otherwise any server side script should just work) for this operation and call the suitelet in your client script using nalpiRequestURL(YOUR_SUITELET_DEPLOYED_URL)
You may additionally want to pass the recordId as URL parameter in your suitelet, and then get the recordId from Suitelet using request.getParameter(paramName)