Google Apps Script Variable Passing - javascript

I'm teaching myself Javascript and needed an explanation on old post that I found very helpful. I apologize in advance if this may seem like a sophomoric post on stackoverflow.
I am referencing this post: Google Apps Script Create form with file upload
I have used the script and am trying to learn it because I have high school students who want to create a google webapp to gather data and information for their projects. Of course I have to learn it myself and explain it. There are two sections I am unsure of. Here's the Code.
var submissionSSKey = '0Agd12jO_f4DrdFFYemZvRERvLWQ4UEhENllaWlVwOFE';
var listitems = ['Select a category','Portrait','Landscape','Night shots','Nature','Various']
var schoollist =['Select School','AFNORTH','Baumholder','Bamberg','Lakenheath MS']
var Panelstyle = {'background':'#dddddd','padding':'40px','borderStyle':'ridge','borderWidth':'15PX','borderColor':'#aaaaaa'}
function doGet() {
var app = UiApp.createApplication().setTitle('i14 Art Submission').setStyleAttribute('padding','50PX');
var panel = app.createFormPanel().setStyleAttributes(Panelstyle).setPixelSize(400, 200);
var title = app.createHTML('<B>I14 Art Submission</B>').setStyleAttribute('color','grey').setStyleAttribute('fontSize','25PX');
var grid = app.createGrid(7,2).setId('grid');
var list1 = app.createListBox().setName('list1');
for(var i in listitems){list1.addItem(listitems[i])}
var Textbox1 = app.createTextBox().setWidth('150px').setName('TB1');
var schllist = app.createListBox().setName('schllist');
for(var i in schoollist){schllist.addItem(schoollist[i])}
var Textbox2 = app.createTextBox().setWidth('150px').setName('TB2');
var email = app.createTextBox().setWidth('150px').setName('mail');
var upLoad = app.createFileUpload().setName('uploadedFile');
var submitButton = app.createSubmitButton('<B>Submit</B>');
var warning = app.createHTML('Please fill in all fields').setStyleAttribute('background','#bbbbbb').setStyleAttribute('fontSize','20px');
//file upload
var cliHandler2 = app.createClientHandler()
.validateLength(Textbox1, 1, 40).validateNotMatches(list1,'Select a category').validateEmail(email).validateNotMatches(upLoad, 'FileUpload')
.forTargets(submitButton).setEnabled(true)
.forTargets(warning).setHTML('Now you can submit your form').setStyleAttribute('background','#99FF99').setStyleAttribute('fontSize','12px');
//Grid layout of items on form
grid.setWidget(0, 1, title)
.setText(1, 0, 'Category')
.setWidget(1, 1, list1.addClickHandler(cliHandler2))
.setText(2, 0, 'School')
.setWidget(2, 1, schllist.addClickHandler(cliHandler2))
.setText(3, 0, 'Name')
.setWidget(3, 1, Textbox1.addClickHandler(cliHandler2))
.setText(4, 0, 'Email')
.setWidget(4, 1, email)
.setText(5, 0, 'File Upload')
.setWidget(5, 1, upLoad.addChangeHandler(cliHandler2))
.setWidget(6, 0, submitButton)
.setWidget(6, 1, warning);
var cliHandler = app.createClientHandler().forTargets(warning).setHTML('<B>PLEASE WAIT WHILE THE FILE IS UPLOADING<B>').setStyleAttribute('background','yellow');
submitButton.addClickHandler(cliHandler).setEnabled(false);
panel.add(grid);
app.add(panel);
return app;
}
function doPost(e) {
var app = UiApp.getActiveApplication();
var ListVal = e.parameter.list1;
var SchoolVal=e.parameter.schllist;
var textVal = e.parameter.TB1;
var Email = e.parameter.mail;
var fileBlob = e.parameter.uploadedFile;
var img = DocsList.createFile(fileBlob);
try{
var folder = DocsList.getFolder('Illuminations 14 Submissions/Art');
}catch(e){DocsList.createFolder('Illuminations 14 Submissions/Art');var folder = DocsList.getFolder('Illuminations 14 Submissions/Art/')}
//var schoolFolder = folder.createFolder(SchoolVal)
img.addToFolder(folder);
img.removeFromFolder(DocsList.getRootFolder())
var sheet = SpreadsheetApp.openById(submissionSSKey).getSheetByName('Art');
var lastRow = sheet.getLastRow();
// var image = sheet.insertImage(img.getUrl(), 4, lastRow+1)
var targetRange = sheet.getRange(lastRow+1, 1, 1, 5).setValues([[SchoolVal,ListVal,textVal,Email,img.getUrl()]]);
//var GDoc = DocumentApp.openByUrl(docurl)
//GDoc.appendTable([['Category : '+ListVal,'Name : '+textVal,'Email : '+Email]])
//var par = GDoc.appendParagraph('IMAGE PREVIEW')
//par.insertInlineImage(1, img.getThumbnail())
//GDoc.appendHorizontalRule();
//GDoc.saveAndClose();
app.add(app.createLabel('Thank you for submitting'));
return app
}
My questions is in function doPost(e), How are the variable declarations able to get values from functio doGet() with a declaration like var ListVal = e.parameter.list1;? Is it the e.parameter? I'm not sure how the e.parameter works. I've got other questions with folder creation, but this is the first step. Thanks in advance for your time.
Radley

The best you can do to clarify your understanding of what is available in the event info object (e in this example) is to visualize it using JSON.stringify().
Simply add a line like Logger.log(JSON.stringify(e)) in the doPost function and look at the Logger after a form submission. You'll see all the e properties that you can retrieve using e.parameter.xxx
here is a view of what you will get : (the file content takes a lot of space but the interesting part is just before it...)
[13-12-06 10:10:27:051 CET] {"queryString":"lib=M_GmTb8T2JCyVLBlttWTHDatIT_UhbT9n&appId=u319190436783&formId=u319190436784&token=AJuLMu1iovLYxDewmZo0Tuv1g2KyC08GJQ:1386320938133&gm1xs=&service=AKfycbymlbEFYZuYIE63cHPT9FlM8WsuWl5fAZFQDdSa9hJ6","parameter":{"gm1xs":"","mail":"testemail#ccc.cc","appId":"u319190436783","lib":"M_GmTb8T2JCyVLBlttWTHDatIT_UhbT9n","list1":"Portrait","token":"AJuLMu1iovLYxDewmZo0Tuv1g2KyC08GJQ:1386320938133","formId":"u319190436784","file":"�PNG\r\n\u001a\n\u0000\u0000\u0000\rIHDR\u0000\u0000\u0000�\u0000\u0000\u0000�\b\u0002\u0000\u0000\u0000Ada�\u0000\u0000\u0000\tpHYs\u0000\u0000\u000b\u0013\u0000\u0000\u000b\u0013\u0001\u0000��\u0018\u0000\u0000\"liCCPPhotoshop ICC profile\u0000\u0000x��EP\u001e^�����������;�`�\u0000\t.\t�A�\u0006\u000b\u001a\u0002!X \u0010 �[���s��T��V�fn}Ϫ�Y��S��uw5\u0000�{�^^nP,\u0000�=�|t\u0014e���M�\u0010\u0001\u0018 \u00028\u0000\u0000nk[_/i--5���<�\u0000\u0000�,����\u001b�\t����\u0016\u0000�\u0016\u0000�����\u001d\u0000H7\u0000#����\u000f\u0000�%\u0000`*���\u000f\u0000�\u0010\u0000\u0000����\u0004\u0000�O\u0000\u0000��?�\u0011\u0000\u0000����\u0004\u0000\u0018\u0000\u0000�����\u0002\u0000�\u0003\u0000\t����\u0011\u0000T*\u0000\u0000U���\u001f\u0000�R\u0000 �x�9{\u0000��\u0007\u0000�����\u001d\u0000�o\u0000\u0000l��v\u00000�\u0003\u0000�l��<��[N���im��\u001f�?\u0001\u0000\u0000�����kHe�g����a\u000f�������\u0005\u0001\u0000�9�(�\u0000\u0000�\u0000\u0000d�\u0007�\u0000>�\u000b\f\u0001\u0015�\u0007~�\u001a�\u0001O�\u0001<���}�\u001f\u0000\u0000�zz\u0005�8;:�QI{y�ٳQ){�r�Q�pqs���ddlB�Ot�\u0013#\u0000\u0000\u0010\u0002���\"\u0010\u0000��\u0006\u0000�����\t\u0000u�\u0000���G�\u000f\u0000N-\u0000mg��>\u0001�xp\u0000\u0000\u0000\u000fP\u0000&�\u0003Ā\u0002�\u0002&�\u000ex�\u0000\u0010\u0005R#\u001e�\u0000M�\u0007��\u0005�\u0005N�\u001d�#\u0010\u0006�A<H\u0006��[�\u0007�A)�\u0002��\u0019��n�\u0019��q0\u0005~�_`\rl�Cp\u0006��=\u0004\u0002A��Cp!�\u0010J\b=�\u0015�\u0003\u0011�H#�!j\u0010\u001d�1�\n�\b��C� ��dH\u0006$\u000f�\u001eR\ri�tB>C� ӐE�:d\u001fr\u000e�� hP<(9�\u0001�\t\u0015�JCU�zPs�#�\u001b\u001a\u0002���Bs�%�:h\u001b�3t\u001c�\u0003�\u0006=�^�\u0000\f\u0015F\u0000���Ä`�0M�\t�\u0001�\u0003��%��`%�\u0006X\u0017l\u00146\u000b[�\u001d�n�\u0010�p����D����l��\"�R��������f�����������Y�E����\u001d�\u0003����+�[���o�_# \u0010 0\"\b\"(!\u0018#� �\"� \u0014\"|#�G�F�D�BDD$FdE\u0014G�D�F�C�G�E�C�C�A�F�D�ă��d��\u0014���T�ԋ4���t���L�,���l�\u001c���\\�܅�\u001dy\u001b�\u001e\u0005\u001b�\u0011E\u001cE\u000f�\u0005%\u001a%\u0007�\u0001e\u0018e\u0019�\u0002\u0015\u0015�\u0006U\u0018U\u001b�\u00195\n5\u0007�\u0011�\u000b�:�-\u001a\u000e\u001a\u000b�,�\u0019�?Z*Z%Z?�\"�\u0005:::\u0003�\u0014�\t�\u001fz*z5� �*�_\f\\\f\u000e\fe\f;�H�|�6�\u0019�\u0013LdLzLiL\u000b�\u0010�,�\u0016��GX�X\fX�X�X\u0011X�X�X\u000bXWظ��ؚ���)�5�c�{8�8\f8�8v8q8�8�8��0\\Z\\Y\\[�X�2�a�m<\u0004<F<e<\u0017�d�z�I�3|\u001c|>|\u0003� �|�\u001e�5\u0002\u0018\u0001\u0003�2�\u001bA\u001aA3�<�\u001d!9�4�=a\"a\u0003�\f�\r\u0011)�\u0014�=Q\u0012�\u0007�\u001fDw�T��Į�����+$p$,$�$�$E$�$G�x�����I�ͤKdP2\u00162\u001d�P�R�\t�+r\nrEr/�\\�A�#\n\u0002\n)\n\u0017�7\u0014�\u0014�\u0012�Δo(�(\u000f�𩤩ܨr���Ψɨ����SOR��0�����|�Y�E�\u0015�u�}C;#{FGI�N\u0017FWK�D�L/D�D�M?J���`�𒡝a���Q�1���q�\t�I�ɛ��i�\u0019�Y�ٕ��y�\u0005����Ē��\u0015�*���Z�:�\u0006�&���V¶���.�\u001e�^˾�A���\u0011���q�I�i�9�������U���\u001b�[�;����ǖ'�g�\u0017�W�7����\u000f\u001f+�=_\u0011�O~\\~u���\u0003�\u0002�\u0002>\u0002\r\u0002�t�V�\u0005�\u000bBxBZB)B_��e�#���oE\u0004D�D�ENE�E]EkD��\u0018�����6�iĭ�ߋ�IPIXI��X�����,�ܐ������ڕf�v���>���i���\u0015�\r�헃�)�%�M������ɯ*�(8*�*�)�+�*�+�+�*�+-(�+�*W+��\b���\f�����n����u�C�U�3՗5�5<4�5���f��\u0016����'m\u0004m-�|�\u001d\u001dn�0�Q]\\]K�\u001a�k=\u0019�4�_�L���\u0003\u0006�\u0006f\u0006�\u00067�r�\u0019�kF�F�F��$���\u001d&�&\u0006&\u0015&W��oM��������\u0019̓��,H,�,z,1-�-[��\f�j�\u001e�5�K��l�m\nl�lem�m\u000f�����ۋ�g��:�;d8�9�;f:�;I:e9\u001d9�:�9�qQr)v�q�t�t}v3t����n������1�I�\u0019�9���\u0015��-�����Gէ�\u0017�k������7�����=#\" ?�o�A`K\u0010v�G�D0Kpb�n�BHy(\\�m�#\u0018uXt�z�t��\bH�M�#$md\\�v�bTU4J�k��\u0018�����X�خ8򸨸�\u0017�/j�1�}�\u0017^��,N�KpN�L�M�M|J�K�̕���b���\u0015���Wϩ\u000e��i\u0002iE�\u0011^{��O�L����\b���T�l{C�&���[˷cY|Y��(���k9j9\u001d�t��s\u001f��~���( +H,�)�+�)�*j(&/N.�{����{��m%\f%Y�\b�\u0001�;e\u0006e��B��\u0015$\u0015�\u0015��\u001e�kU:UCՂ��5d5i��Z���:���z��\u0006���\u001f\b>$7�F�ƃ&���f��\u0016�����\u001f\u000bZq[�� m�mg�N�k\u001d�\u001dӝ*�\u0003]�]��8>UvSw����������>���]�{�\u001f}v�9`9�k�hpnH{hrXu�ˈ����h�\u0017�/�c\"c�_����\u000b��M�O�~���:)0��]�{ǔ�T״�t����Y�ّ9��\u001f\u001a?����.�-�����g)`��W�2�r�\n�J�*�j�o��\u001f�\u0004�z���'6t7~m�n\u001en�n=l���d�R�V���u�+�O\u001d�\u001el\u001fz\u001d�\u001f�\u001fc\u001f\u0017�0�|<�:�83:������<����r�J�j�����&�/�ߪ[���;û���\u0007ć�G�Ǯ'է�g��g/k\u001fk\u0000�?m%��\u0001��J\u0000Ѝ\u0001��\u0002\u0000���~�_�A\u0000�\u0002\u0000�A)��\u0018Bڡ��#�/�\f�\u001a\u000e\u000f.\fn\u000f^\u000f�\u0017�\u001d�\u0000\u0011\r1\u0014�\u0010�\u0002i\u0006Y\u0001�\u0007�\u0017�\u001a�\u0016�\u0000�\b-\u0013\u001d\u0013=\u0015\u0003\u0003�\u0015&\u0016f&\u0016\t�;l&�\u0016\u001cq�q\\\u0013�C�\b|<�Z\u0002\u0005�u�H\"j�!b7\u0012\u0002�AR_2F�U�<\nCJR�u�\u001a� \u001aeZ\n�\u001b�\u0019�\u000f\fi�\u001eL\u001a�\u001c,�,���l3�\u001c]��\\-�m<=�_����\u0005��\b��E4D�Œū%�$K]ˠ�\u0012�Q�3(�(�+q(s�������3j�jRj�j\u0013�`��!�C��\fn\r��΍�L�M�͎̏-�,/��l��hvD�\f\u000eB�jN���.E���\u0016�/=��ؽU|\u001c|c��\u0003~\u0006^\u0005�p�����'DTD\u000eFm�#b��$_X�G�|��9q3\u0019>��j�gZ����L�7�ou�B��s����3\u0014�\u0016F\u00175\u0016���.�+\r,�)_�ĩR�\u000e�i�ݫ�l0��8�\fi\u0011�\u0018���v�����U�鸇�ק���q#~0uhq�~����W�q牾I��>S�g8g��N�5\u0017>,b.y��Z�Y}������\u0016���]����P������\u001f���K�����[ڻ�'����f��R�Q�Q�Q�V����d�b�fСե�#�'6 4�3�1�2�0E7C3ǰ��Ķ·&���e��\u0017sPv4rrq�t�t�t����c���\u001b��ȗ�O�_-�,�=(\"8-�8�)�s�l�V�u4R\fI,{��\u000b�xǗa\t鉕I��?RNR\u0011�h^��\u001bg\u0004ff�i����C����_T0Qx_����}^�l\u0019Z�RE\\�#5�F�6�n�\u0001��vcN�z\u000b�ǀ��v�\u000e�ΦO�n���>H����A�!��Q�/�c+�\u0012\u0013�&��\u001d��g�g����\u0016�\u0017Y�^��Z1[\u001d\\c]���=�+��z�xXp�w�z����\u0005�e�5�Mϭ���C�����)�+������1��hPh\u0012k�jc� �Bu\u001f����\u0018\u001c\u0019�\u001am\u0018�6Y1]6�e�l��r�������\u000eŞԁ�Q���9ƥ�u�m�\u0003ٓ�K���'���߂�] y�T�]HBh]�T�U$I�d�}LrlS��\f\t��IEɣ)���i����s2\u00063Oޒf)f��ϝ�{(`-4)J(�x�WB\\�R\u0016Z^[�\\�V-^�^[X7Y��Ѻ)�y�底�ͼ=�c���\u0013o�kOY��~�φ\u0003Y���D#f�%_���GOLM�~\u000f����M�ۛ�_(Y\u0004K濺WHWC/�Kl�n!m{�,�)�\u001d�\u001c\u0015�\u0010���!=/��\u001a�����kyp}�x~\u0006���\u0002\u0000\u0000\u0010\t\u0000P\u0001\u00000�\u0007#I\n�<)\u0000�\u0000�\u0001\u0000hI\u0001�'\u0005 /l\u0001$�\t#��\u0001\f�\u001f~\u0000\u0000\u0001P\u0000\u0007\u0010\u00002#\u0003X��=�\u0000\u000b�\u0002B#\u0012(\u0002-`\fl�\u001b\b\u00041�\u0015�\u0005�\u0019�o�\u00178\u0000�\u0010$\b\u0011�\t\"\fQ��B�!Q�\fH\u0005�\u0013�\r�\u000e���B��\u0002P5�-4\u0004�\u000e���CB��P`�01�\u0001�\u000b�\u0004+����`�p�p�p�p�p1p�p�p�p��x�<�Z�\u001e�)��c�{\b�\b\f\b\n\b�\bq\be\bC\b[�p�t�r�v�/\u0010�\u0011G\u0010w�\u0010�\u0018�������j�&���1�9�����3�[� _�\u0010�\b�\u0018���\u0014�����<�R�ʠڢơ�����!���������5�M�����\u001b�\u0007��B_A ��ÈǨ��q���Ƀ��\u0019���ً��\u0005�Ō����\u0006�\u0003k\u0019\u001b`�b+b�b�a�`/`��P���8�$�4���\\�\u0012��Z���Ɲ�=���\u0013�3ŋ�+�\u001b�;�������\u000f�/����$#$`%� �!�\"�$X!\u0004�t�J���i�-��wD\u0014D2D�D�D�D�DW�������/���'��I\bIDI�H�H�I&I.H�H�ImI\u0013H\u001bHgIo�(�\u0014���2�:���\u0011�9�\r�#�+�'�o(()�(|(�)�)N)I(�(=)�)G)/�(�Ԩ��*�f�!�\u001c�f�IԝԻ4\u00044r4�4�43�PZnZk�t�\u0001�s:Z:=�\u0017tmt��������\u001f��\u0019�\u0018\u0014\u0018�\u0019�\u0018~3�2*0�060n0\u00110�2E2}d�g�`�eN`�e�daf�dy�2�\ne\u0015f�b�d]e�gSc�c��v���n˞�>ˁ�!�\u0011���q���i͙�9DžΥ�\u0015���늛�ۙ��{���G�'��\u000b/�W�7�������ϑ��o���_�?�B\u0000I#N J�[� ���`��\u0010���P�В0����k�\t\u0011d\u0011y�\u0018�^�{QAQ_�F�#1f1{�\u0012�Uq\u0012qC�L��\u0012�\u0012J\u0012q\u0012�\u0012\u000f�B���\u001f$\u000f�\u0018�l�����\t�u�Ӥ'd�d�ebd�d\u001ed�e\u0003e?ʞ�q�y���\u001d�3�;ȗ�o*�(X+�S�H�h�X���D�d�T���L�l�\\���B�b��Ne]�F�N�\\uG�I�E�N�D�K�G��F�F�&DSN��\u0016����[�Em2m+�2�=\u001d6\u001do�V�;]\t�X�/z�z:z�z+�4����\u0017\u0006�\u0006�\u0006Æ��چن�FtF�F�F��R�/�'M�M�M�L�LyMCM\u0007�P�t��Ͷ�����{,\u0010,4,�-�,�-},���4�r�6�Y���l�mtm\nmvmyl�lG����*�����\u0013�g\u001d(\u001c�\u001dZ\u0

Related

Put variable name in JSON Array (fetched by an api)

I am very new to Javascript but I will try to put this in convenient way. I am having this api where I am fetching the rank of a crypto (Ripple; currently ranked 7 and is subject to change overtime ), code below:
function myFunction() {
var url = "https://api.coinpaprika.com/v1/coins/xrp-xrp";
var XRPresponse = UrlFetchApp.fetch(url);
var XRPjson = XRPresponse.getContentText();
var XRPdata = JSON.parse(XRPjson);
var XRPrank = XRPdata.rank;
}
Now this is another function for an api where I extract other infos (having 5000+ crytos listed, including ripple)
function myXRP() {
var url = "https://api.coinpaprika.com/v1/tickers";
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var XRP = data[7].symbol;
// Here instead of [7], I need to put the value extracted from XRPrank above so that whenever the rank is changed I get the latest value on data.[].
If someone could please advise.
In JavaScript there are several ways to achieve what you are looking for. The following is an adaptation of your current code with what I think are the minimal changes that you have to do, 1. use return followed by XRPrank 2. Call myFunction from myXRP and replace the data index by XRPrank.
function myFunction() {
var url = "https://api.coinpaprika.com/v1/coins/xrp-xrp";
var XRPresponse = UrlFetchApp.fetch(url);
var XRPjson = XRPresponse.getContentText();
var XRPdata = JSON.parse(XRPjson);
var XRPrank = XRPdata.rank;
return XRPrank; // add this
}
function myXRP() {
var url = "https://api.coinpaprika.com/v1/tickers";
var response = UrlFetchApp.fetch(url);
var json = response.getContentText();
var data = JSON.parse(json);
var XRPrank = myFunction(); // add this
// var XRP = data[7].symbol; instead of this
var XRP = data[XRPrank].symbol; // use this
}
Resources
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Functions

How to update URL address using ASP when based on JSON object

I'm making an application of a list of races in a table, this information is gotten from a JSON api. Upon selecting a race in a table I need a window to pop up with the name of the race in the url address bar, so something like asp?=race_name at the end.
How would I go about completing this?
I've looked this up but can't seem to find an answer, my guess is I'm googling the wrong thing as I'm not good at explaining
for (let i = 0; i < jsonObj.length; i++) {
document.getElementById(jsonObj[i].id).onclick = function () {
var newWin = window.open("","","width=700,height=700");
newWin.onload = function () {
var doc = newWin.document; // Create new document in window
var raceName = document.createElement('h3');
var distance = document.createElement('p');
var location = document.createElement('p');
var curPos = document.createElement('p');
var difference = document.createElement('p');
raceName.textContent = jsonObj[i].race_name;
distance.textContent = jsonObj[i].distance;
location.textContent = jsonObj[i].venue_name;
doc.body.appendChild(raceName);
doc.body.appendChild(distance);
doc.body.appendChild(location);
}
}
Here the window pops up and includes the correct information, I now just need to include code that would update the url address to include race name.

Google Scripts - How to call the correct sheet

I´m learning how to use the Google Scripts, I saw a video on the youtube and I wrote this code based on the video. It will be a dashboard, but the problem I have is: In this spreadsheet, I have more than one Sheet. How can I "tell" the code which sheet it would have to check? In my case the Sheet ID is 8.
I think this would be the only "mistake" in the code!
Thanks for helping!
function doGet() {
// Identify the spreadsheet where the data is stored.
var ss = SpreadsheetApp.openById('0AjizIuAuEzaydFlsRDRrTkZSekROaWNZNV9QbjRDdUE')
var data = ss.getDataRange();
// Create all the filters
var clienteFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(1).build();
var pedidoFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(2).build();
var necessidadeFilter = Charts.newCategoryFilter().setFilterColumnIndex(3).build();
var entregaFilter = Charts.newCategoryFilter().setFilterColumnIndex(4).build();
var notaconsultorFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(5).build();
var notaentregadorFilter = Charts.newNumberRangeFilter().setFilterColumnIndex(6).build();
var recomendariaFilter = Charts.newCategoryFilter().setFilterColumnIndex(8).build();
var atencaoFilter = Charts.newCategoryFilter().setFilterColumnIndex(9).build();
var servicosFilter = Charts.newCategoryFilter().setFilterColumnIndex(10).build();
var entregadorFilter = Charts.newCategoryFilter().setFilterColumnIndex(11).build();
// Create all the charts
var pieChart = Charts.newPieChart()
.setDataViewDefinition(Charts.newDataViewDefinition().setColumns([11,6]))
.build();
// Create the dashboard
var dashboard = Charts.newDashboardPanel().setDataTable(data)
.bind([clienteFilter, pedidoFilter, necessidadeFilter, entregaFilter, notaconsultorFilter, notaentregadorFilter, recomendariaFilter, atencaoFilter, servicosFilter, entregadorFilter],[pieChart])
.build();
// Create the webapp and bind together the filters and charts
var app = UiApp.createApplication();
var filterPanel = app.createVerticalPanel();
var chartPanel = app.createHorizontalPanel();
filterPanel.add(clienteFilter).add(pedidoFilter).add(necessidadeFilter).add(entregaFilter).add(notaconsultorFilter).add(notaentregadorFilter).add(recomendariaFilter).add(atencaoFilter).add(servicosFilter).add(entregadorFilter).setSpacing(10);
chartPanel.add(pieChart).setSpacing(10);
// Format the dashboard layout
dashboard.add(app.createVerticalPanel().add(filterPanel).add(chartPanel));
app.add(dashboard);
return app;
}
in your code , ss comes for a spreadSheet object, which is -way of speaking - the "parent" of the included sheets.
This class (spreadsheet object) has a couple of methods to get sheets that are described in the documentation, for example getSheetByName('name of the sheet') or getSheets() which returns an array of sheet objects. In this case you can chose which one you use with getSheets()[number]

How to Make a list on Google SpreadSheet of all files in a Google Drive folder

I have a Folder With more than 2000 Files.. And i Need to make a List of all these files on google spreadsheet.. I Found online some Scripts.. but they're not completely working.
When i hit "RUN" i just get a list of 250 Files.
Reading on Google Developers page i found some things about enabling Google Drive advanced services (and i did it)..
And i think i could solve this problem using something named "tokens"??
I don't know.. i'm not a programmer, and i barely know english..
i Tried editing this script making a fusion of what i found online.. But anything works.. i just get errors that i can't even understand..
So.. is there someone able to fix it?
function listFilesInFolder() {
var folder = DocsList.getFolder("Film");
var contents = folder.getFiles();
var file;
var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Nome", "Data", "Dimensione"]);
for (var i = 0; i < contents.length; i++) {
file = contents[i];
if (file.getFileType() == "SPREADSHEET") {
continue;
}
data = [
file.getName(),
file.getDateCreated(),
file.getSize(),
];
sheet.appendRow(data);
}
};
This Script works for at least 2200 Files :)
function listFilesInFolder(id) {
var folder = DriveApp.getFolderById('MyFolderID');
var contents = folder.getFiles();
var file;
var name;
var sheet = SpreadsheetApp.getActiveSheet();
var date;
var size;
sheet.clear();
sheet.appendRow(["Nome", "Data", "Dimensione"]);
while(contents.hasNext()) {
file = contents.next();
name = file.getName();
date = file.getDateCreated()
size = file.getSize()
data = [name, date, size]
sheet.appendRow(data);
}
};
The answer above appends a row in every iteration wich is particularly slow and there is a chance you will exceed the maximum execution time (see best practices)) so here is a version that uses an array to collect data and writes the array using a single setValues() .
The other issue is that it gets all the files in your drive, not in the folder you chose...
so below is a version that gets all files that are not Google documents, ie it counts only files that take space (images, pdf...) with a maximum of 4000 files.
full code below :
function listFilesInFolder() {
var folder = DocsList.getFolderById('0B3qSFd3iikE3MS0yMzU4YjQ4NC04NjQxLTQyYmEtYTExNC1lMWVhNTZiMjlhMmI');
var file;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
var data = [];
data.push(["Name", "Data", "Size", "url"]);
var filesresult = folder.getFilesByTypeForPaging(DocsList.FileType.OTHER, 4000);
var files = filesresult.getFiles();
Logger.log(files.length);
for (var i in files) {
file = files[i];
data.push([
file.getName(),
file.getDateCreated(),
file.getSize(),
file.getUrl()
]);
}
sheet.getRange(1,1,data.length,data[0].length).setValues(data);
}
Paging is what you're looking for. When you have a large number of results (like 2000 files), you generally divide the request into 'pages', either to show the user page by page or in this case, to stay within the API limits.
The 'token' isn't a big deal.. it's just how your script remembers the page number while it's dealing with the current page.
So there's information about this here: https://developers.google.com/apps-script/reference/docs-list/files-result
The script at the top of the page is quite apt to your situation. Your script becomes something like...
function listFilesInFolder() {
var folder = DocsList.getFolder("Film");
//var contents = folder.getFiles();
var file;
//var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Nome", "Data", "Dimensione"]);
var pageSize = 200;
var files = null;
var token = null; // use a null token for the first lookup
do {
var result = DocsList.getAllFilesForPaging(pageSize, token);
files = result.getFiles();
token = result.getToken();
for (var i = 0; i < files.length; i++) {
//Logger.log(files[i].getName());
file = files[i];
if (file.getFileType() == "SPREADSHEET") {
continue;
}
data = [
file.getName(),
file.getDateCreated(),
file.getSize(),
];
sheet.appendRow(data);
}
} while (files.length >= pageSize);
};
I'm not promising this will work.. but I'm sure you can sort it out. Basically the "while loop" on that page replaces the "for loop" from your script. The loop on that page just calls Logger.log(), so you swap that with the sheet.appendRow(data)
I've taken the script suggested by Jonathan Livingston and made some edits.
Now it:
can take a name of a sheet with future report. It can make a new sheet if it doesn't exist,
gives more parameters, including list of editors (e-mails)
Here's the code:
function TESTlistFilesInFolder() {
listFilesInFolder("0B0pifCWzjn-ib0ZWT2x1ekNOWAY", "Files Report");
// ^^^^^^^^ folder ID ^^^^^^^^^ ^sheet Name^
}
// original script: http://stackoverflow.com/a/25730522/5372400
function listFilesInFolder(id, sheetName) {
sheetName = sheetName || id;
var sheet = createSheetIfNotExists(sheetName);
var folder = DriveApp.getFolderById(id);
var contents = folder.getFiles();
sheet.clear();
sheet.appendRow(["Name", "CreatedDate", "Last Updated", "Id", "Url", "Editors", "Viewers", "Owner", "Access", "Permission", "Size"]);
var data = [];
var file;
var info = [];
while(contents.hasNext()) {
data = [];
file = contents.next();
data.push(file.getName());
data.push(file.getDateCreated());
data.push(file.getLastUpdated());
data.push(file.getId());
data.push(file.getUrl());
// convert to string: http://www.w3schools.com/jsref/jsref_join.asp
data.push(getEmails(file.getEditors()).join());
data.push(getEmails(file.getViewers()).join());
data.push(getEmails(file.getOwner()).join());
data.push(file.getSharingAccess());
data.push(file.getSharingPermission());
data.push(file.getSize());
info.push(data);
}
var rows = info.length;
var cols = info[0].length;
var range = sheet.getRange(2,1,rows,cols);
range.setValues(info);
};
function createSheetIfNotExists(name) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
try {ss.setActiveSheet(ss.getSheetByName(name));}
catch (e) {ss.insertSheet(name);}
var sheet = ss.getSheetByName(name);
return sheet;
}
// users: https://developers.google.com/apps-script/reference/base/user
function getEmails(users) {
var emails = [];
var user;
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
if (!Array.isArray(users)) { users = [users]; }
for (var i = 0; i < users.length; i++) {
user = users[i];
emails.push(user.getEmail());
}
return emails;
}

Display output of Javascript function

I have a javascript function that outputs the date modified of a sharepoint list.
Here is my code:
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var list = lists.getByTitle("Tasks");
ctx.load(list, "LastItemModifiedDate");
ctx.executeQueryAsync(
function() {
var lastmodified = list.get_lastItemModifiedDate();
},
function() {}
);
Which I got from this link. But I am unsure of how to display the output from the function. I tried to display the output in the html tag but still no luck.
Have you tried something like this after you capture the lastmodified date?
// Names are generic and can be changed
var displayElement = document.getElementById("lastModifiedDisplay");
displayElement.innerHTML = lastmodified
document.getElementById

Categories

Resources