บริการอสังหาริมทรัพย์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บริการพร็อพเพอร์ตี้ช่วยให้คุณจัดเก็บ
ข้อมูลอย่างง่ายในคู่คีย์-ค่าที่กำหนดขอบเขตไว้สำหรับสคริปต์ 1 รายการ ผู้ใช้สคริปต์ 1 ราย หรือ
เอกสาร 1 รายการที่ใช้ส่วนเสริม โดยปกติจะใช้เพื่อจัดเก็บการกำหนดค่าของนักพัฒนาแอปหรือค่ากำหนดของผู้ใช้ ระบบจะไม่แชร์พร็อพเพอร์ตี้
ระหว่างสคริปต์ต่างๆ
หากต้องการดูโควต้าต่อวันและขีดจำกัดพื้นที่เก็บข้อมูลสำหรับบริการพร็อพเพอร์ตี้ โปรดดูโควต้าสำหรับบริการของ Google
การเปรียบเทียบร้านค้าของพร็อพเพอร์ตี้
ออบเจ็กต์
PropertiesService
ส่วนกลางมี 3 วิธี ซึ่งแต่ละวิธีจะแสดงออบเจ็กต์
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()
จัดการพร็อพเพอร์ตี้ของสคริปต์ด้วยตนเอง
คุณเพิ่มพร็อพเพอร์ตี้ที่กำหนดเองได้สูงสุด 50 รายการด้วยตนเองเป็นสตริงในคู่คีย์-ค่าจากหน้าการตั้งค่าโปรเจ็กต์ หากต้องการเพิ่มพร็อพเพอร์ตี้มากกว่า 50 รายการ คุณจะต้องเพิ่มแบบเป็นโปรแกรมโดยใช้วิธีที่อธิบายไว้ข้างต้นในส่วนการบันทึกข้อมูล
เมื่อตั้งค่าพร็อพเพอร์ตี้สคริปต์จากหน้าการตั้งค่าโปรเจ็กต์ คุณจะอ้างอิงตัวแปรสคริปต์ไม่ได้
เพิ่มพร็อพเพอร์ตี้ของสคริปต์
- เปิดโปรเจ็กต์ Apps Script
- คลิกการตั้งค่าโปรเจ็กต์
ทางด้านซ้าย
- หากต้องการเพิ่มพร็อพเพอร์ตี้แรก ให้คลิกเพิ่มพร็อพเพอร์ตี้ของสคริปต์ในส่วนพร็อพเพอร์ตี้ของสคริปต์
- หากต้องการเพิ่มพร็อพเพอร์ตี้ที่ 2 และพร็อพเพอร์ตี้ต่อๆ ไป ให้คลิกแก้ไขพร็อพเพอร์ตี้ของสคริปต์ > เพิ่มพร็อพเพอร์ตี้ของสคริปต์ในส่วนพร็อพเพอร์ตี้ของสคริปต์
- สําหรับพร็อพเพอร์ตี้ ให้ป้อนชื่อคีย์
- สําหรับค่า ให้ป้อนค่าสําหรับคีย์
- (ไม่บังคับ) หากต้องการเพิ่มพร็อพเพอร์ตี้ ให้คลิกเพิ่มพร็อพเพอร์ตี้ของสคริปต์
- คลิกบันทึกพร็อพเพอร์ตี้ของสคริปต์
แก้ไขพร็อพเพอร์ตี้ของสคริปต์
- เปิดโปรเจ็กต์ Apps Script
- คลิกการตั้งค่าโปรเจ็กต์
ทางด้านซ้าย
- ในส่วนพร็อพเพอร์ตี้ของสคริปต์ ให้คลิกแก้ไขพร็อพเพอร์ตี้ของสคริปต์
- ทำการเปลี่ยนแปลงชื่อคีย์และค่าคีย์สำหรับแต่ละพร็อพเพอร์ตี้ที่คุณต้องการเปลี่ยนแปลง
- คลิกบันทึกพร็อพเพอร์ตี้ของสคริปต์
ลบพร็อพเพอร์ตี้ของสคริปต์
- เปิดโปรเจ็กต์ Apps Script
- คลิกการตั้งค่าโปรเจ็กต์
ทางด้านซ้าย
- ในส่วนพร็อพเพอร์ตี้ของสคริปต์ ให้คลิกแก้ไขพร็อพเพอร์ตี้ของสคริปต์
- คลิกนำออก close ข้างพร็อพเพอร์ตี้ที่ต้องการลบ
- คลิกบันทึกพร็อพเพอร์ตี้ของสคริปต์
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\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**."]]