I want to create and delete properties from the PropertiesService
using code in Google Apps Script. Can this be done?
I know that you can retrieve properties and set them as well, but I want to create one. However I am not seeing any code for creating a property, e.g.:
PropertiesService.getDocumentProperties.createProperty(foo)
Can anyone help?
Here's some syntax on how to create, and delete properties:
function setProperties(){
//create properties
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.setProperty("cow", "moo");
var userProperties = PropertiesService.getUserProperties();
userProperties.setProperty("nickname", "sad");
var docProperties = PropertiesService.getDocumentProperties();
docProperties.setProperty("theme", "dark")
}
function deleteProperty(){
// Deletes properties.
var scriptProperties = PropertiesService.getScriptProperties();
scriptProperties.deleteProperty("cow");
var userProperties = PropertiesService.getUserProperties();
userProperties.deleteProperty("nickname");
var docProperties = PropertiesService.getDocumentProperties();
docProperties.deleteProperty("theme");
}
In order for you to understand these sample Implementation, I would highly recommend that you read and understand the three types of properties. how and when to use them. You can find more information about these by visiting the official documentation below:
References: