How do I update the approval reply email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2015 09:34 AM
We currently have approvals through email. In the email there is a link 'click here to approve' and 'click here to reject'. When you select this it opens a new email and puts a subject with the change number and either approve or reject.
Is there a way for me to change the subject it defaults to?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-18-2015 10:15 AM
Hi Kumar,
I'd advise you against doing it this way. Trying to parse data out of an email is finicky. You'll find that people will put in invalid data, or they'll forget to fill it out, or they'll send it in a format you don't expect. Parsing from the body of the message is going to lead to incidents and weird behavior.
If you want them to give you good data, send them a link to a form where you can validate data. Give them a reference field to fill out, or use a script to verify an entered value is valid before accepting the update. Otherwise you can't guarantee the results.
If you must accept the input via e-mail, you'll need to try a regex to pull the data out. There is no good simple regex for the general case; real-world email addresses can be very complicated. You'll find that your solution works in the specific test cases, and fails in production in surprising and irritating ways. Just know what you are getting in to.
I don't want to encourage this use-case, but I will give you a starting point and some advice.
Start by finding your "Please provide email address" string, and getting it's index within the body of your message:
var EMAIL_PROMPT = "Please provide Approver1 email:";
var start = email.body.indexOf(EMAIL_PROMPT);
if(start > -1)
start = start + EMAIL_PROMPT.length;
You'll want to parse from the end of the prompt (the "start" value above) to the end of the email body, but only if the prompt is actually int he reply. You could go to the end of the line, but you'd miss things like people putting email address on the next line, or email addresses that span multiple lines, or hard-coded breaks added by older email systems for lines that are too long.
You will have an easier time if you know the format of the email address ahead of time, but you have to account for various formats, people making typos, or people leaving the address out entirely. You might be expecting "sally.approver@mycompany.com" and your user copies it our of Outlook as "Sally Approver <sally.approver@mycompany.com>". Or they might put in something invalid like "XXXX@example.com" or "I think it's my.boss@yourplace.com but maybe it's gene.hackman@supermanlives.com?". Those are the pitfalls when you accept free-form data like that.
I hope you aren't using this address as anything important, like verifying an identity. If you are taking this in and associating some action to that e-mail address, you need to make sure the person is actually authorized to perform the action, and that they want your automated process taking it for them. If some user puts "admin@company.com" into that field, and you are auto-approving some request as the admin user then you are introducing a security hole. Suddenly your admin is approving brand new iPhone 6s's for everyone who knows how to send an email to your instance and they don't even know it.
Here are some links that may be useful for you:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substring
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
https://stackoverflow.com/questions/14440444/extract-all-email-addresses-from-bulk-text-using-jquery
https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
If you really need to get a piece of important information from someone, have them fill it out in the instance, in a form field where you can include look-ups and validation and explanatory text and error messages. Otherwise future-you, in 2 months at 3:00 AM on a Tuesday morning, is going to be really upset at current-you.
Don't make future-you regret being past-you.