Skip to content

Commit

Permalink
Implemented check for settings being set
Browse files Browse the repository at this point in the history
This includes opening the sidebar if the settings are not set.
  • Loading branch information
Reisclef committed Feb 12, 2016
1 parent 7fb34d0 commit 4515abd
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions refreshdata.gs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
* If there are more response lines than info lines. Add the missing formulae based on the 2nd row in Information (first row of data)
*/
function refreshData(){
var lastResponse = getLastFormEntry();
var lastCalc = getLastInformationRow();
if (lastResponse > lastCalc){
var prefs = getPreferences();
var copiedRow = getRowFormulae(prefs['rowToCopy']);
for (var r = lastCalc; r < lastResponse; r++){
var infoSheet = activateSheet(prefs['targetSheet']);
var rowToChange = r + 1;
copiedRow.copyTo(infoSheet.getRange(rowToChange + ":" + rowToChange));
if (checkPreferencesSet())
{
var lastResponse = getLastFormEntry();
var lastCalc = getLastInformationRow();
if (lastResponse > lastCalc){
var prefs = getPreferences();
var copiedRow = getRowFormulae(prefs['rowToCopy']);
for (var r = lastCalc; r < lastResponse; r++){
var infoSheet = activateSheet(prefs['targetSheet']);
var rowToChange = r + 1;
copiedRow.copyTo(infoSheet.getRange(rowToChange + ":" + rowToChange));
}
Browser.msgBox(lastResponse - lastCalc + " rows added.",Browser.Buttons.OK);
}
else{
Browser.msgBox("Nothing to refresh.",Browser.Buttons.OK);
}
Browser.msgBox(lastResponse - lastCalc + " rows added.",Browser.Buttons.OK);
}
else{
Browser.msgBox("Nothing to refresh.",Browser.Buttons.OK);
else {
displayOptions();
Browser.msgBox("You must set the source sheet, target sheet, and row to copy.",Browser.Buttons.OK);
}
}

Expand Down Expand Up @@ -92,7 +99,7 @@ function displayOptions(){
* Return user's preferences for source and target spreadsheet
*/
function getPreferences() {
var userProperties = PropertiesService.getUserProperties();
var userProperties = PropertiesService.getDocumentProperties();
var prefs = {
sourceSheet: userProperties.getProperty('sourceSheet'),
targetSheet: userProperties.getProperty('targetSheet'),
Expand All @@ -105,8 +112,25 @@ function getPreferences() {
* Set the user's preferences based on the function arguments
*/
function setPreferences(source,target,row) {
var userProperties = PropertiesService.getUserProperties()
var userProperties = PropertiesService.getDocumentProperties();
userProperties.setProperty('sourceSheet', source);
userProperties.setProperty('targetSheet', target);
userProperties.setProperty('rowToCopy', row);
}

/*
* Returns true if all settings are set, otherwise false.
*/
function checkPreferencesSet() {
var valid = true;
var settings = Array('sourceSheet','targetSheet','rowToCopy');
var i = 0;
var props = PropertiesService.getDocumentProperties();
while (i < settings.length && valid) {
if (props.getProperty(settings[i]) == null) {
valid = false;
}
i++;
}
return valid;
}

0 comments on commit 4515abd

Please sign in to comment.