2012-06-14 52 views
0

我剛開始使用gApps腳本,並且在嘗試設置我的用戶界面以禁用任務處理時的提交按鈕時遇到了兩個與我的代碼(下面)有關的問題。Google Apps腳本 - submitButton UI元素 - 發生意外錯誤

  1. 當試圖加載腳本時,偶爾會出現以下錯誤:「遇到錯誤:意外錯誤發生」。這個錯誤是不一致的,因爲我需要做的就是刷新腳本,然後它會爲我加載。當我沒有改變代碼時,它真的讓我感到困擾,有時候它有效,有時不會。

  2. 當第三個最後一行//button_submit.setEnabled(true);未註釋時,每次嘗試加載腳本時都會發生錯誤。

我試圖弄清楚什麼是錯的,我注意到的getElementById()似乎並沒有被分配正確的UI類型的提交按鈕。我不確定這是否是問題的原因,但我懷疑這不是因爲我在測試腳本中看到了相同的行爲,以查看是否可以從較簡單的基礎複製該問題。

我很感激您對可能導致此問題的任何反饋。

由於

克里斯乙-P

Logging output 

populate_assign_list spinner.getId():spinner 
populate_assign_list spinner.getType():Image 
populate_assign_list button_submit.getId():button_submit 
populate_assign_list button_submit.getType():Generic 
doGet button_submit.getId():spinner 
doGet button_submit.getType():Image 
doGet button_submit.getId():button_submit 
doGet button_submit.getType():SubmitButton 

//define global script property variables 
var prop_home_folder_id;  //String - Contains the home folder's ID string 
var prop_subject_folder_names; //Array of Strings - Listing of folder names 
var prop_subject_folder_ids; //Array of Strings - Listing of folder IDs associated with folder names 
var prop_submisison_ss_ids; //Array of Strings - Losting of sumission spreadsheet IDs 
var prop_allow_anon_submit; //Flag - Allow manual entry of email address (ie. non domain access) Default to FALSE 

function save_script_prop_(home_folder_id, subject_folder_names, subject_folder_ids, submisison_ss_ids, allow_anon_submit) { 
    //array values must be sent to this function as comma separated strings ie <array>.join(',') 
    if (home_folder_id != null) ScriptProperties.setProperty("home_folder_id", home_folder_id); 
    if (subject_folder_names != null) ScriptProperties.setProperty("subject_folder_names", subject_folder_names); 
    if (subject_folder_ids != null) ScriptProperties.setProperty("subject_folder_ids", subject_folder_ids); 
    if (submisison_ss_ids != null) ScriptProperties.setProperty("submisison_ss_ids", submisison_ss_ids); 
    if (allow_anon_submit != null) ScriptProperties.setProperty("allow_anon_submit", allow_anon_submit); 
} 

function load_script_prop_() { 
    /* 
    prop_home_folder_id = ScriptProperties.getProperty("home_folder_id"); 
    prop_subject_folder_names = ScriptProperties.getProperty("subject_folder_names").split(","); 
    prop_subject_folder_ids = ScriptProperties.getProperty("subject_folder_ids").split(","); 
    prop_submisison_ss_ids = ScriptProperties.getProperty("submisison_ss_ids").split(","); 
    prop_allow_anon_submit = ScriptProperties.getProperty("allow_anon_submit"); 
    //*/ 
    prop_home_folder_id = ""; 
    prop_subject_folder_names = ["1","2","3"]; 
    prop_subject_folder_ids = ["1","2","3"]; 
    prop_submisison_ss_ids = ["a","b","c"]; 
    prop_allow_anon_submit = false; 
} 




function doPost(e) { 
    var app = UiApp.getActiveApplication(); 
    app.add(app.createLabel("Form submitted")); 
    return app; 
} 

function doGet() { 
    load_script_prop_(); 
    var testing_message = ""; 

    //create ui app and panels 
    var app = UiApp.createApplication().setTitle("Assignment Submission"); 
    var v_panel = app.createVerticalPanel(); 
    v_panel.setSpacing(20); 
    var layout_grid = app.createGrid(5,2); 
    var form_panel = app.createFormPanel(); 
    var tab_panel_upload = app.createTabPanel().setId("tab_panel_upload"); 
    var v_panel_upload_file = app.createVerticalPanel().setTag(0); //Tag refrenced the number of upload elements currently in the tab 
    var v_panel_upload_gdoc = app.createVerticalPanel().setTag(0); //Tag refrenced the number of gdoc elements currently in the tab 


    //create menu objects 
    var spinner = app.createImage("http://www.worldmsday.org/1000-faces/images/whatami/spinner.gif").setVisible(false).setId("spinner"); 
    var datebox_submission = app.createDateBox().setId("submission_datebox").setValue(new Date()).setEnabled(false); 
    var textbox_user = app.createTextBox().setId("textbox_user").setName("textbox_user").setValue(Session.getUser().getEmail()).setEnabled(false); 

    var lb_subject_folder = app.createListBox().setId("lb_subject_folder").setName("lb_subject_folder"); 
    lb_subject_folder.setVisibleItemCount(1); 
    for (var i in prop_subject_folder_names) lb_subject_folder.addItem(prop_subject_folder_names[i], i); 
    lb_subject_folder.setSelectedIndex(0); 

    var lb_assign_list = app.createListBox().setId("lb_assign_list").setName("lb_assign_list"); 
    lb_assign_list.setVisibleItemCount(1); 
    populate_assign_list(); 
    lb_assign_list.setSelectedIndex(0); 

    var button_submit = app.createSubmitButton("Submit").setId("button_submit"); 
    Logger.log("doGet button_submit.getId():"+spinner.getId()); 
    Logger.log("doGet button_submit.getType():"+spinner.getType()); 
    Logger.log("doGet button_submit.getId():"+button_submit.getId()); 
    Logger.log("doGet button_submit.getType():"+button_submit.getType()); 


    //button_submit.setEnabled(false); 
    //button_submit.setEnabled(true); 

    var upload_1 = app.createFileUpload().setName("upload_1"); 
    var gdoc_1 = app.createLabel("Not Yet Implemented"); 




    //create menu handlers 
    var handler_lb_subject_folder_spinner = app.createClientHandler().forTargets(spinner).setVisible(true); 
    handler_lb_subject_folder_spinner.forTargets([lb_assign_list, tab_panel_upload]).setVisible(false); 
    handler_lb_subject_folder_spinner.forTargets(button_submit).setEnabled(false); 

    var handler_lb_subject_folder = app.createServerHandler("populate_assign_list").addCallbackElement(v_panel); 
    lb_subject_folder.addChangeHandler(handler_lb_subject_folder_spinner); 
    lb_subject_folder.addChangeHandler(handler_lb_subject_folder); 
    //need to add an onchange handler for subject folder listbox which updates the assignment selection listbox. 


    //add ui objects to ui 
    layout_grid.setText(0,0, "Date: "); 
    layout_grid.setWidget(0, 1, datebox_submission); 
    layout_grid.setText(1,0, "Name: "); 
    //layout_grid.setWidget(1, 1, ""); 
    layout_grid.setText(2,0, "Email Address: "); 
    layout_grid.setWidget(2, 1, textbox_user); 
    layout_grid.setText(3,0, "Course: "); 
    layout_grid.setWidget(3, 1, lb_subject_folder); 
    layout_grid.setText(4,0, "Assignment: "); 
    layout_grid.setWidget(4, 1, lb_assign_list); 
    v_panel.add(layout_grid); 

    v_panel.add(spinner); 

    v_panel_upload_file.add(upload_1); 
    tab_panel_upload.add(v_panel_upload_file, "Upload File"); 

    v_panel_upload_file.add(gdoc_1); 
    tab_panel_upload.add(v_panel_upload_gdoc, "Share gDoc"); 
    tab_panel_upload.selectTab(0); 
    v_panel.add(tab_panel_upload); 


    v_panel.add(button_submit); 

    form_panel.add(v_panel); 
    app.add(form_panel); 



    var testing_label = app.createLabel("No Test Output").setStyleAttribute("textAlign", "center"); 
    if (testing_message != "") debug_label.setText(testing_label); 
    app.add(testing_label); 

    return(app); 
} 

function populate_assign_list(e) { 
    load_script_prop_(); 

    if (e == null) subject_id=0; 
    else subject_id = e.parameter.lb_subject_folder; 

    var app = UiApp.getActiveApplication(); 
    var lb_assign_list = app.getElementById("lb_assign_list"); 
    lb_assign_list.clear(); 

    var assign_list = ["x","y","z" ]; 

    for (var i = 1; i < assign_list.length; i++) { 
    lb_assign_list.addItem(assign_list[i] ); 
    } 


    lb_assign_list.setVisible(true); 
    var spinner = app.getElementById("spinner").setVisible(false); 
    Logger.log("populate_assign_list spinner.getId():" + spinner.getId()); 
    Logger.log("populate_assign_list spinner.getType():" + spinner.getType()); 
    app.getElementById("tab_panel_upload").setVisible(true); 

    var button_submit = app.getElementById("button_submit"); 
    Logger.log("populate_assign_list button_submit.getId():"+button_submit.getId()); 
    Logger.log("populate_assign_list button_submit.getType():"+button_submit.getType()); 
    //button_submit.setEnabled(true); 

    return app; 
} 

回答

1

分而治之 -

我有過這樣的錯誤了幾次,我可以追查 的原因是「分而治之」的唯一途徑。

...

原因我知道的...

A)用於不同類型的對象相同的對象ID,即使舊的對象已被刪除。

B)無效顏色值

C)與createApplication

創建該應用對象兩次誤差看起來是一種捕獲的所有錯誤消息。 它也看起來是一個客戶端錯誤,所以不確定日誌會有幫助。

+0

我很懷疑。我希望我能夠忽略某些錯誤/愚蠢的事情,這會很容易解決。 –