خدمات املاک
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
سرویس Properties به شما امکان میدهد دادههای ساده را در جفتهای کلید-مقدار با محدوده یک اسکریپت، یک کاربر از یک اسکریپت یا یک سند که در آن یک افزونه استفاده میشود، ذخیره کنید. معمولاً برای ذخیره تنظیمات برنامهنویس یا تنظیمات برگزیده کاربر استفاده میشود. ویژگی ها هرگز بین اسکریپت ها به اشتراک گذاشته نمی شوند.
برای مشاهده سهمیههای روزانه و محدودیتهای فضای ذخیرهسازی برای سرویس Properties، به سهمیههای خدمات Google مراجعه کنید.
مقایسه فروشگاه های املاک
شیء جهانی PropertiesService
سه روش ارائه می دهد که هر کدام یک شیء Properties
مشابه اما با حقوق دسترسی متفاوت را برمی گرداند، همانطور که در جدول زیر نشان داده شده است:
| ویژگی های اسکریپت | ویژگی های کاربر | ویژگی های سند |
---|
روش دسترسی | getScriptProperties() | getUserProperties() | getDocumentProperties() |
داده های به اشتراک گذاشته شده بین | همه کاربران یک اسکریپت، افزونه یا برنامه وب | کاربر فعلی یک اسکریپت، افزونه یا برنامه وب | همه کاربران یک افزونه در سند باز |
به طور معمول برای استفاده می شود | دادههای پیکربندی گسترده برنامه، مانند نام کاربری و رمز عبور پایگاه داده خارجی برنامهنویس | تنظیمات خاص کاربر، مانند واحدهای متریک یا امپریال | دادههای خاص سند، مانند URL منبع برای نمودار جاسازی شده |
سرویس Properties تمام داده ها را به صورت رشته ها در جفت های کلید-مقدار ذخیره می کند. انواع دادههایی که قبلاً رشتهای نیستند، بهطور خودکار به رشتهها تبدیل میشوند، از جمله روشهای موجود در اشیاء ذخیرهشده.
ذخیره داده ها
برای ذخیره یک مقدار واحد، روش Properties.setProperty(key, value)
ذخیره مناسب را فراخوانی کنید، همانطور که در مثال زیر نشان داده شده است:
برای ذخیره داده ها به صورت انبوه، نقشه ای از جفت های کلید-مقدار را به Properties.setProperties(properties)
ارسال کنید. هر جفت کلید-مقدار شی در پارامتر به عنوان یک ویژگی جداگانه ذخیره می شود:
خواندن داده ها
برای بازیابی یک مقداری که قبلاً ذخیره کرده اید، Properties.getProperty(key)
را فراخوانی کنید:
برای بازیابی تمام مقادیر موجود در فروشگاه ویژگی فعلی، Properties.getProperties()
را فراخوانی کنید:
اصلاح داده ها
متدهای getProperty()
و getProperties()
یک کپی از دادههای ذخیره شده را برمیگردانند، نه یک نمای زنده، بنابراین تغییر شیء برگشتی، مقدار را در ذخیرهگاه ویژگی بهروزرسانی نمیکند. برای بهروزرسانی دادهها در فروشگاه، کافی است دوباره آن را ذخیره کنید:
در حال حذف داده ها
برای حذف یک مقدار، Properties.deleteProperty(key)
را فراخوانی کنید:
برای حذف تمام خواص موجود در فروشگاه فعلی، Properties.deleteAllProperties()
را فراخوانی کنید:
ویژگی های اسکریپت را به صورت دستی مدیریت کنید
می توانید به صورت دستی تا پنجاه ویژگی سفارشی را به عنوان رشته ها در جفت کلید-مقدار از صفحه تنظیمات پروژه اضافه کنید. برای افزودن بیش از پنجاه ویژگی، باید با استفاده از روشهایی که در بالا در Saving data توضیح داده شد، آنها را به صورت برنامهنویسی اضافه کنید. وقتی ویژگی های اسکریپت را از صفحه تنظیمات پروژه تنظیم می کنید، نمی توانید به متغیرهای اسکریپت ارجاع دهید.
ویژگی های اسکریپت را اضافه کنید
- پروژه Apps Script خود را باز کنید.
- در سمت چپ، روی تنظیمات پروژه کلیک کنید
. - برای افزودن اولین ویژگی، در زیر ویژگی های اسکریپت ، روی افزودن ویژگی اسکریپت کلیک کنید.
- برای افزودن ویژگیهای دوم و بعدی، در زیر ویژگیهای اسکریپت ، روی ویرایش ویژگیهای اسکریپت > افزودن ویژگی اسکریپت کلیک کنید.
- برای Property ، نام کلید را وارد کنید.
- برای مقدار ، مقدار کلید را وارد کنید.
- (اختیاری) برای افزودن ویژگی های بیشتر، روی افزودن ویژگی اسکریپت کلیک کنید.
- روی ذخیره خصوصیات اسکریپت کلیک کنید.
ویژگی های اسکریپت را ویرایش کنید
- پروژه Apps Script خود را باز کنید.
- در سمت چپ، روی تنظیمات پروژه کلیک کنید
. - در زیر ویژگی های اسکریپت ، روی ویرایش ویژگی های اسکریپت کلیک کنید.
- برای هر ویژگی که می خواهید تغییر دهید، نام کلید و مقدار کلید را تغییر دهید.
- روی ذخیره خصوصیات اسکریپت کلیک کنید.
ویژگی های اسکریپت را حذف کنید
- پروژه Apps Script خود را باز کنید.
- در سمت چپ، روی تنظیمات پروژه کلیک کنید
. - در زیر ویژگی های اسکریپت ، روی ویرایش ویژگی های اسکریپت کلیک کنید.
- در کنار ویژگی که میخواهید حذف کنید، روی Remove close کلیک کنید.
- روی ذخیره خصوصیات اسکریپت کلیک کنید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-29 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eThe Properties service allows you to store simple data as key-value pairs, with separate stores for script, user, and document properties.\u003c/p\u003e\n"],["\u003cp\u003eData is stored as strings and automatically converted if it's a different data type, with access varying depending on the chosen property store.\u003c/p\u003e\n"],["\u003cp\u003eYou can save, read, modify, and delete data within these property stores using specific methods provided by the Properties service.\u003c/p\u003e\n"],["\u003cp\u003eScript properties can also be managed manually through the project settings page for a limited number of custom properties.\u003c/p\u003e\n"]]],[],null,["# Properties Service\n\nThe [Properties service](/apps-script/reference/properties) lets you store\nsimple data in key-value pairs scoped to one script, one user of a script, or\none document in which an [add-on](/workspace/add-ons/overview) is used. It is\ntypically used to store developer configuration or user preferences. Properties\nare never shared between scripts.\n\nTo view the daily quotas and storage limits for the Properties service, see\n[Quotas for Google Services](/apps-script/guides/services/quotas).\n\nComparison of property stores\n-----------------------------\n\nThe\n[`PropertiesService`](/apps-script/reference/properties/properties-service)\nglobal object offers three methods, each of which returns a similar\n[`Properties`](/apps-script/reference/properties/properties)\nobject but with different access rights, as shown in the following table:\n\n| | Script Properties | User Properties | Document Properties |\n|--------------------|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|\n| Method to access | [getScriptProperties()](/apps-script/reference/properties/properties-service#getScriptProperties()) | [getUserProperties()](/apps-script/reference/properties/properties-service#getUserProperties()) | [getDocumentProperties()](/apps-script/reference/properties/properties-service#getDocumentProperties()) |\n| Data shared among | All users of a script, add-on, or web app | The current user of a script, add-on, or web app | All users of an add-on in the open document |\n| Typically used for | App-wide configuration data, like the username and password for the developer's external database | User-specific settings, like metric or imperial units | Document-specific data, like the source URL for an embedded chart |\n\nData format\n-----------\n\nThe Properties service stores all data as strings in key-value pairs. Data types\nthat are not already strings are automatically converted to strings, including\nmethods contained within saved objects.\n\nSaving data\n-----------\n\nTo save a single value, call the method [`Properties.setProperty(key,\nvalue)`](/apps-script/reference/properties/properties#setProperty(String,String))\nof the appropriate store, as shown in the following example: \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Set a property in each of the three property stores.\n const scriptProperties = PropertiesService.getScriptProperties();\n const userProperties = PropertiesService.getUserProperties();\n const documentProperties = PropertiesService.getDocumentProperties();\n\n scriptProperties.setProperty('SERVER_URL', 'http://www.example.com/');\n userProperties.setProperty('DISPLAY_UNITS', 'metric');\n documentProperties.setProperty('SOURCE_DATA_ID',\n '1j3GgabZvXUF177W0Zs_2v--H6SPCQb4pmZ6HsTZYT5k');\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nTo save data in bulk, pass a map of key-value pairs to\n[`Properties.setProperties(properties)`](/apps-script/reference/properties/properties#setProperties(Object)).\nEach key-value pair of the object in the parameter is stored as a separate\nproperty: \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Set multiple script properties in one call.\n const scriptProperties = PropertiesService.getScriptProperties();\n scriptProperties.setProperties({\n 'cow': 'moo',\n 'sheep': 'baa',\n 'chicken': 'cluck'\n });\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nReading data\n------------\n\nTo retrieve a single value that you have previously saved, call\n[`Properties.getProperty(key)`](/apps-script/reference/properties/properties#getProperty(String)): \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Get the value for the user property 'DISPLAY_UNITS'.\n const userProperties = PropertiesService.getUserProperties();\n const units = userProperties.getProperty('DISPLAY_UNITS');\n console.log('values of units %s', units);\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nTo retrieve all values in the current property store, call\n[`Properties.getProperties()`](/apps-script/reference/properties/properties#getProperties()): \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Get multiple script properties in one call, then log them all.\n const scriptProperties = PropertiesService.getScriptProperties();\n const data = scriptProperties.getProperties();\n for (const key in data) {\n console.log('Key: %s, Value: %s', key, data[key]);\n }\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nModifying data\n--------------\n\nThe methods `getProperty()` and `getProperties()` return a copy of the stored\ndata, not a live view, so changing the returned object will not update the value\nin the property store. To update the data in the store, simply save it again: \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Change the unit type in the user property 'DISPLAY_UNITS'.\n const userProperties = PropertiesService.getUserProperties();\n let units = userProperties.getProperty('DISPLAY_UNITS');\n units = 'imperial'; // Only changes local value, not stored value.\n userProperties.setProperty('DISPLAY_UNITS', units); // Updates stored value.\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nDeleting data\n-------------\n\nTo delete a single value, call\n[`Properties.deleteProperty(key)`](/apps-script/reference/properties/properties#deleteProperty(String)): \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Delete the user property 'DISPLAY_UNITS'.\n const userProperties = PropertiesService.getUserProperties();\n userProperties.deleteProperty('DISPLAY_UNITS');\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nTo delete all properties in the current store, call\n[`Properties.deleteAllProperties()`](/apps-script/reference/properties/properties#deleteAllProperties()): \nservice/propertyService.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/service/propertyService.gs) \n\n```javascript\ntry {\n // Get user properties in the current script.\n const userProperties = PropertiesService.getUserProperties();\n // Delete all user properties in the current script.\n userProperties.deleteAllProperties();\n} catch (err) {\n // TODO (developer) - Handle exception\n console.log('Failed with error %s', err.message);\n}\n```\n\nManage script properties manually\n---------------------------------\n\nYou can manually add up to fifty custom properties, as strings in key-value\npairs, from the project settings page. To add more than fifty properties, you\nneed to add them programmatically using the methods described above in\n[Saving data](#saving-data).\nWhen you set script properties from the project settings page, you can't\nreference script variables.\n\n### Add script properties\n\n1. Open your Apps Script project.\n2. At the left, click **Project Settings** .\n3. To add the first property, under **Script Properties** click **Add script property**.\n4. To add second and subsequent properties, under **Script Properties** click **Edit script properties** \\\u003e **Add script property**.\n5. For **Property**, enter the key name.\n6. For **Value**, enter the value for the key.\n7. (Optional) To add more properties, click **Add script property**.\n8. Click **Save script properties**.\n\n### Edit script properties\n\n1. Open your Apps Script project.\n2. At the left, click **Project Settings** .\n3. Under **Script Properties** , click **Edit script properties**.\n4. Make changes to the key name and key value for each property you want to change.\n5. Click **Save script properties**.\n\n### Delete script properties\n\n1. Open your Apps Script project.\n2. At the left, click **Project Settings** .\n3. Under **Script Properties** , click **Edit script properties**.\n4. Next to the property that you want to delete, click Remove close.\n5. Click **Save script properties**."]]