Create Application using Google Apps Script

 


The given code is written in Google Apps Script. It has three functions, namely doGet(), include(filename), and sub(vl).

The doGet() function returns an HTML template created from the 'index' file. It sets the title of the template to 'SGS-L Tracker' and adds a meta tag to set the viewport to the width of the device and initial scale to 1. It also allows all websites to frame the template.

The include(filename) function returns the content of an HTML file.

The sub(vl) function takes a parameter vl and uses it to search for a value in the first column of the 'Sheet1' sheet of the active spreadsheet. It creates a table with the values in the matching row and returns the HTML code for that table.

function doGet(){ return HtmlService.createTemplateFromFile('index').evaluate() .setTitle('SGS-L Tracker') .addMetaTag('viewport', 'width=device-width , initial-scale=1') .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL) } var dt = Utilities.formatDate(new Date(),Intl.DateTimeFormat().resolvedOptions().timeZone, 'yyyy-MM-dd HH:mm:ss'); function include(filename) { return HtmlService.createHtmlOutputFromFile(filename).getContent(); } function sub(vl){ var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1'); var dl = ws.getDataRange().getValues(); var tb = ''; for(var i=1; i<dl.length ; i++){ if(dl[i][0]==vl){ tb+='<table cellspacing="0"><tbody id="profile"><tr><td colspan="1" class="subLabel">UNID: </td><td colspan="5" id="res_unid">'+dl[i][0]+'</td></tr><tr><td class="subLabel">SHEI: </td><td colspan="5" id="res_shei">'+dl[i][1]+'</td></tr><tr><td class="subLabel">DHEI: </td><td colspan="5" id="res_dhei">'+dl[i][2]+'</td></tr><tr><td class="subLabel">SCHOLARSHIP STATUS: </td><td colspan="2" id="res_sstatus">'+dl[i][3]+'</td><td class="subLabel">SCHOLARSHIP TYPE: </td><td colspan="2" id="res_stype">'+dl[i][4]+'</td></tr></tbody><tbody id="laStatus"><tr><td class="label" colspan="6">LIVING ALLOWANCE</td></tr><tr><td colspan="6" class="ay3rd1617">AY 2016-2017 3RD TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rd">'+dl[i][5]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rd">'+dl[i][6]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rd">'+dl[i][7]+'</td></tr><tr><td colspan="6" class="ay4th1617">AY 2016-2017 4TH TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4th">'+dl[i][8]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4th">'+dl[i][9]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4th">'+dl[i][10]+'</td></tr><tr><td colspan="6" class="ay1st1718">AY 2017-2018 1ST TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1st">'+dl[i][11]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1st">'+dl[i][12]+'</td></tr> <tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1st">'+dl[i][13]+'</td></tr><tr><td colspan="6" class="ay2nd1718">AY 2017-2018 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2nd">'+dl[i][14]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2nd">'+dl[i][15]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2nd">'+dl[i][16]+'</td></tr><tr><td colspan="6" class="ay3rd1718">AY 2017-2018 3rd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rda">'+dl[i][17]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rda">'+dl[i][18]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rda">'+dl[i][19]+'</td></tr><tr><td colspan="6" class="ay4th1718">AY 2017-2018 4th TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4tha">'+dl[i][20]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4tha">'+dl[i][21]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4tha">'+dl[i][22]+'</td></tr> <tr><td colspan="6" class="ay1st1819">AY 2018-2019 1ST TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1sta">'+dl[i][23]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1sta">'+dl[i][24]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1sta">'+dl[i][25]+'</td></tr><tr><td colspan="6" class="ay2nd1819">AY 2018-2019 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2nda">'+dl[i][26]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2nda">'+dl[i][27]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2nda">'+dl[i][28]+'</td></tr><tr><td colspan="6" class="ay3rd1819">AY 2018-2019 3rd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status3rdb">'+dl[i][29]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem3rdb">'+dl[i][30]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act3rdb">'+dl[i][31]+'</td></tr> <tr><td colspan="6" class="ay4th1819">AY 2018-2019 4th TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status4thb">'+dl[i][32]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem4thb">'+dl[i][33]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act4thb">'+dl[i][34]+'</td></tr><tr><td colspan="6" class="ay1st1920">AY 2019-2020 1st TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status1stb">'+dl[i][35]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem1stb">'+dl[i][36]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act1stb">'+dl[i][37]+'</td></tr> <tr><td colspan="6" class="ay2nd1920">AY 2019-2020 2nd TERM</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="res_status2ndb">'+dl[i][38]+'</td></tr><tr><td colspan="1" class="subLabel">CONSOLIDATED ISSUES</td><td colspan="5" id="res_rem2ndb">'+dl[i][39]+'</td></tr><tr><td colspan="1" class="subLabel">NEXT STEPS</td><td colspan="5" id="res_act2ndb">'+dl[i][40]+'</td></tr></tbody><tbody id="tdStatus"><tr><td class="label" colspan="6">THESIS / DISSERTATION</td></tr><tr><td colspan="6" class="td80">EIGHTY PERCENT (80%)</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="td_status80"><pre>'+dl[i][41]+'</pre></td></tr><tr><td colspan="1" class="subLabel">REMARKS</td><td colspan="5" id="td_remarks80"><pre>'+dl[i][42]+'</pre></td></tr><tr><td colspan="6" class="td20">TWENTY PERCENT (20%)</td></tr><tr><td colspan="1" class="subLabel">STATUS</td><td colspan="5" id="td_status20"><pre>'+dl[i][43]+'</pre></td></tr><tr><td colspan="1" class="subLabel">REMARKS</td><td colspan="5" id="td_remarks20">'+dl[i][44]+'</td></tr></tbody></table><center><font face=times size=1px>Date of issue: '+dt+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;℗Power by CodyLab Technology. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; www.codylab.blogspot.com</font></center>'; }}; return tb; }

This is an HTML code snippet that contains a form for inputting a UNID and viewing the status associated with it. The form is centered on the page and includes an image header, a subheader, a container for the input form and a container for displaying the result.

The form includes an input field for the UNID, with an associated label and a placeholder. There is also a button for submitting the form, which triggers the JavaScript function view_status() when clicked.

The view_status() function retrieves the value of the UNID input field and displays a loading message in the result container. It then calls a Google Apps Script function sub() with the UNID value as an argument, using the google.script.run method. If the sub() function succeeds, the res() function is called with the result value as an argument, which is then displayed in the result container. If the sub() function fails, the res() function is called with an empty argument, and a "No record!" message is displayed in the result container.

The HTML code also includes a meta tag for setting the viewport width and initial scale, and two link tags for importing CSS stylesheets from external sources. The include('css') statement is used to include additional CSS code that is shown in next snippet.

<!DOCTYPE html> <html> <head> <base target="_top"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"> <?!= include('css'); ?> </head> <body> <center><header> <div id="imgheader"> <img src="https://i.postimg.cc/FRqpWNmd/K12-Generic-Form-Banner-preview.png"width="60%"> </div> </header> <div id="subheader"> </div> <div id="cont"> <p> Input your UNID and click the button to view your status.</p> <label>UNID : </label> <input type="text" id="UNID" onkeydown="if(event.keyCode == 13){document.getElementById('view').click()}" placeholder="e.x. 2016b-111111"> <button onclick="view_status()" id="view">View Status </button> </div> <div id="result" style="display: block;"> </div> </center> <script> function view_status(){ var vl = document.getElementById('UNID').value; if(vl!=''){ var lo = '<i class="fa fa-circle-o-notch fa-spin" style="font-size:12px"></i> Fetching...'; document.getElementById("result").innerHTML = lo; google.script.run.withFailureHandler(res) .withSuccessHandler(res) .sub(vl);}else{document.getElementById("result").innerHTML='Please enter UNID.'}} function res(v){ if(v===''){ var re = 'No record!';}else{var re = v;} document.getElementById("result").innerHTML = re;} </script> </body> </html>

This is a CSS code block, which is used to style the HTML elements on a webpage. The code includes various styling rules for different elements, such as font styles, background colors, padding, border, and more. These styles are applied to elements with specific IDs or class names, such as "cont", "view", "subLabel", "td", etc. This particular code block includes styles for tables, buttons, and labels with different background colors and font weights. The code also includes a rule for hiding an element with an ID of "result".
<style> body { font-family: Montserrat, Proxima Nova; background-color: #FFFFF7; } #cont { width: 60%; margin-top: 5px; background-color: white; border: 1px solid black; font-family: 18px; padding-bottom: 10px; padding-top: 10px; } #view { padding: 10px; font-size: 15px; background-color: #006CB6; border: 0; border-radius: 5px; box-shadow: 3px 3px 3px #777777; margin-left: 10px; color: white; } button { appearance: auto; writing-mode: horizontal-tb !important; font-style: ; font-variant-ligatures: ; font-variant-caps: ; font-variant-numeric: ; font-variant-east-asian: ; font-weight: ; font-stretch: ; font-size: ; font-family: ; text-rendering: auto; color: buttontext; letter-spacing: normal; word-spacing: normal; line-height: normal; text-transform: none; text-indent: 0px; text-shadow: none; display: inline-block; text-align: center; align-items: flex-start; cursor: default; box-sizing: border-box; background-color: buttonface; margin: 0em; padding: 1px 6px; border-width: 2px; border-style: outset; border-color: buttonborder; border-image: initial; } .subLabel { background-color: grey; color: white; font-weight: bold; text-align: left; } td { width: 20%; padding: 5px; height: 15px; margin: -3px; border: 0.1px solid #cccccc; } user agent stylesheet td { display: table-cell; vertical-align: inherit; } user agent stylesheet table { border-collapse: separate; text-indent: initial; border-spacing: 2px; } #result { display: none; font-size: 13px; width: 60%; margin-top: 5px; } user agent stylesheet center { text-align: -webkit-center; } .label { background-color: #222222; color: white; font-weight: bolder; text-align: center; font-size: 20px; } .ay3rd1617 { text-align: center; background-color: #f7786b; color: white; font-weight: bold; }.ay4th1617 { text-align: center; background-color: #c56055; color: white; font-weight: bold; } .ay1st1718 { text-align: center; background-color: #84bd00; color: white; font-weight: bold; } .ay2nd1718 { background-color: #699700; text-align: center; color: white; font-weight: bold; } .ay3rd1718 { background-color: #4f7100; text-align: center; color: white; font-weight: bold; } .ay4th1718 { background-color: #344b00; text-align: center; color: white; font-weight: bold; } .ay1st1819 { text-align: center; background-color: #5F4B8B; color: white; font-weight: bold; } .ay2nd1819 { text-align: center; background-color: #55437d; color: white; font-weight: bold; } .ay3rd1819 { text-align: center; background-color: #423461; color: white; font-weight: bold; } .ay4th1819 { text-align: center; color: white; font-weight: bold; background: #392d53; } .ay1st1920 { text-align: center; color: white; font-weight: bold; background: #3c8dbc; } .ay2nd1920 { text-align: center; color: white; font-weight: bold; background: #33779e; } .td80 { text-align: center; background-color: #073763; color: white; font-weight: bold; } .td20 { text-align: center; background-color: #20124d; color: white; font-weight: bold; } </style>

Post a Comment

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.