调用setProperties后Script properties损坏,无法编辑保存报错
setProperties() I’ve run into similar head-scratching issues with Google Apps Script’s Script Properties before, so I feel your frustration. Let’s walk through targeted fixes for the "Failed to save Project Properties for script." error you’re facing after calling PropertiesService.getScriptProperties().setProperties(properties):
1. Validate the properties Object You’re Setting
First, double-check the data being passed to setProperties—bad data is often the root cause:
- Hidden or special characters: Line breaks, tabs, or Unicode control characters in keys/values can break the UI’s ability to parse properties. Log the object with
JSON.stringify(properties)and inspect it for odd, unreadable content. - Exceeding size limits: Script Properties have a total storage cap of 96KB, and individual values can’t exceed 12KB. If your batch
setPropertiespushes past these limits, it might silently corrupt the property store before the UI fails. Try splitting properties into smaller chunks and usingsetProperty()for each entry instead. - Malformed keys: Avoid empty string keys, and be cautious with non-ASCII characters—while technically allowed, they’ve caused UI parsing issues for me in the past.
2. Rule Out Environment & Permission Glitches
- Test in incognito mode: Browser extensions or cached auth sessions often interfere with the script editor’s UI. Open the script in an incognito window, log in, and try editing properties again—this is more reliable than just clearing cache.
- Re-authorize the script: Stale permissions can trigger unexpected backend errors. Run any dummy function (like
function testAuth() {}) to trigger the OAuth re-authorization flow, complete it, then try editing properties again. - Confirm ownership/permissions: Make sure you’re the project owner or have full edit access. If collaborating, ask the owner to test editing properties to rule out permission-related blocks.
3. Force a Full Reset of the Property Store
If the property store itself is corrupted:
- Wipe all properties via code: Run this one-time function to completely clear the property store:
After running it, refresh the script editor and try adding properties manually again.function clearAllScriptProperties() { PropertiesService.getScriptProperties().deleteAllProperties(); } - Clone the project: If the original project’s property store is irreparably damaged (rare but possible), create a new Google Apps Script project, copy all your code over, and set up properties fresh in the new project. This bypasses any project-specific corruption.
4. Check for Google Service Outages
Occasionally, this can be a temporary backend bug in Google Apps Script. Verify if there are ongoing outages for Google Apps Script through Google’s official status channels. If it’s a widespread issue, you’ll just need to wait for Google to resolve it.
If none of these steps work, submit a detailed bug report through Google’s official Apps Script support channels, including your script ID, exact steps to reproduce the problem, and the error message you’re seeing.
内容的提问来源于stack exchange,提问作者Thraug

