Reputation: 1037
I am using document properties in my google apps script to store the mysql database connection string and get the error TypeError: Cannot call method "setProperties" of null at line 2 not sure what the reason might be.
dbmysqlconndev = PropertiesService.getDocumentProperties();
dbmysqlconndev.setProperties({
'mysqlUrl': 'jdbc:mysql://dbserverdev;databaseName=sample',
'mysqlUser': 'username',
'mysqlPassword': 'password'});
var keys = dbmysqlconndev.getKeys();
for (var i = 0; i < keys.length; i++) {
dbmysqlconndev.getProperty(keys[i]);
}
var mysqlurl = dbmysqlconndev.getProperty(keys[0]);
var mysqlusr = dbmysqlconndev.getProperty(keys[1]);
var mysqlpwd = dbmysqlconndev.getProperty(keys[2]);
Upvotes: 1
Views: 1449
Reputation:
The reason is, as the error message says, that dbmysqlconndev
is null. Now, what would PropertiesService.getDocumentProperties()
return null? Let's read its documentation:
It is only available if the script is published and executing as an add-on or if it is bound to a Google file type. When document properties are not available this method returns null.
So that would be why: are you probably executing this as a stand-alone script. Use getScriptProperties
instead of getDocumentProperties
.
Upvotes: 2