I am trying to write a app script that add some custom properties to the file that stored in shared Drive. After trying multiple ways and reading through the documentationtext, I still can’t succeed adding or getting properties of a file.
Here is my coding for adding the AppProperties:
function addAppProperty(fileId) {
try {
let file = {
'appProperties': {
'department': 'Sales'
}
};
// Updates a file to add an app property.
file = Drive.Files.update(file, fileId, null, {'fields': 'id,appProperties'});
console.log(
'ID: %s, appProperties: %s',
file.id,
JSON.stringify(file.appProperties, null, 2));
} catch (err) {
// TODO (developer) - Handle exception
console.log('Failed with error %s', err.message);
}
}
which is from the documentation, this works well, but when I try to return the properties of a file and search for property, I’ve encountered many errors:
function getProperty() {
var files = DriveApp.searchFiles('properties has { key="department" and value="Sales" }');
if(files.hasNext) {
var file = files.next();
console.log(file.getName());
}
else{
console.log("No file founded")
}
}
With error Exception: Invalid argument: q
, regard to this line var file = files.next();
I have no clue how to solve this problem, Very appreciate to any kind of Help!
Yunlong is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.