Just apply the blocks i have shown to your app ....
If you want to use a google apps script then you will need something like this: