Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh menu conflicts custom menus with onOpen(){ SpreadsheetsApp.getUi() #18

Open
waterenergy0 opened this issue Sep 10, 2020 · 0 comments

Comments

@waterenergy0
Copy link

Hi Folks,
Thank you all for creating a maintaining this awesome repo. This is my crashcourse in Javascript/GAS, as well as Github, and I've only pulled out a little bit of my hair so far.

As you know, the existing repo has a section of code that among other things, creates a new menu item that refreshes the data from the Robinhood_get custom function calls by updating the time in a cell in the 'Refresh' sheet. A great feature, but it seems to interfere with an improvement I'm trying to make that would call for a different menu to be added.

I want to create a menu with userProperties, so end user can input their username, password, and device_token without having to do any scripting. I've gotten as far as creating the menu. However, once implemented into the robinhood-google-sheets script, I get this funny error that I haven't been able to troubleshoot on my own.

Basically, either one or the other custom menu will load in the menu bar, but not both.

Any help would be appreciated.

Here's the existing onOpen() code that is in the repo, which creates the "Refresh Data" menu:

function onOpen() { var cache = CacheService.getScriptCache(); cache.remove('accessToken'); var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var refreshSheet = spreadsheet.getSheetByName('Params'); if (refreshSheet === null) { refreshSheet = spreadsheet.insertSheet('Params'); } var entries = [{ name: 'Refresh Data', functionName: 'refreshLastUpdate_' }]; spreadsheet.addMenu('Refresh Data', entries); }

This is my proposed additional menu:

`var scriptProperties = PropertiesService.getScriptProperties();
var userProperties = PropertiesService.getUserProperties();

function onOpen(){
SpreadsheetApp.getUi()
.createMenu('Azeem')
.addSubMenu(SpreadsheetApp.getUi().createMenu('Robinhood Credentials')
.addItem('Robinhood Username', 'userUsername')
.addItem('Robinhood Password', 'userPassword')
.addItem('Robinhood Device Token', 'userDeviceToken'))
.addSubMenu(SpreadsheetApp.getUi().createMenu('Show Credentials')
.addItem('Show All Robinhood User Keys', 'alertAllUserProperties'))
.addSubMenu(SpreadsheetApp.getUi().createMenu('Delete Credentials')
.addItem('Delete all Robinhood User Account Info', 'deleteAllUser'))
.addToUi();
}

function userUsername(){
var ui = SpreadsheetApp.getUi();
var userUsername = ui.prompt('Robinhood Username (usually an email address) ' , ui.ButtonSet.OK_CANCEL);
userProperties.setProperty('RH Username', userUsername.getResponseText());
}

function userPassword(){
var ui = SpreadsheetApp.getUi();
var userPassword = ui.prompt('Robinhood Password ' , ui.ButtonSet.OK_CANCEL);
userProperties.setProperty('RH Password', userPassword.getResponseText());
}

function userDeviceToken(){
var ui = SpreadsheetApp.getUi();
var userDeviceToken = ui.prompt('Robinhood Device_Token (See Instructions on the first Tab) ' , ui.ButtonSet.OK_CANCEL);
userProperties.setProperty('RH Device Token', userDeviceToken.getResponseText());
}

// ----------- Operations ---------------------------

function deleteAllUser(){
userProperties.deleteAllProperties();
}

function alertAllUserProperties(){
var ui = SpreadsheetApp.getUi();
var stringUserProperties = '';
var userdata = userProperties.getProperties();
for (var userkey in userdata){
stringUserProperties = stringUserProperties + '(userKey): ' + userkey + ' Value: ' + userdata[userkey] + '\n';
}
ui.alert(stringUserProperties);
}

function alertAllUserKeys(){
var ui = SpreadsheetApp.getUi();
var stringUserKeys= '';
var allUserKeys = userProperties.getKeys()
Logger.log('allUserKeys: ' + allUserKeys);
for (var userkey in allUserKeys){
stringUserKeys = stringUserKeys + '(userKey): ' + allUserKeys[userkey] + '\n';
}
ui.alert(stringUserKeys);
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant