אובייקט המאפיינים משמש כממשק לגישה למאפייני משתמש, מסמך או סקריפט. סוג המאפיין הספציפי תלוי בשיטה מבין שלוש השיטות של PropertiesService שהסקריפט קרא לה: PropertiesService.getDocumentProperties(), PropertiesService.getUserProperties() או PropertiesService.getScriptProperties().
אי אפשר לשתף מאפיינים בין סקריפטים. מידע נוסף על סוגי מאפיינים זמין במדריך לשירות Properties.
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
delete | Properties | מחיקה של כל הנכסים בחנות הנוכחית Properties. |
delete | Properties | מוחק את המאפיין עם המפתח הנתון בחנות הנוכחית Properties. |
get | String[] | מקבל את כל המפתחות בחנות Properties הנוכחית. |
get | Object | מקבל עותק של כל צמדי ערך/מפתח בחנות הנוכחית Properties. |
get | String | מחזירה את הערך שמשויך למפתח הנתון בחנות Properties הנוכחית, או null אם לא קיים מפתח כזה. |
set | Properties | מגדיר את כל צמדי מפתח/ערך מהאובייקט הנתון בחנות Properties הנוכחית. |
set | Properties | מגדירה את כל צמדי מפתח/ערך מהאובייקט הנתון בחנות Properties הנוכחית,
אפשר גם למחוק את כל המאפיינים האחרים בחנות. |
set | Properties | מגדיר את צמד המפתח/ערך שצוין בחנות הנוכחית Properties. |
תיעוד מפורט
deleteAllProperties()
מחיקה של כל הנכסים בחנות הנוכחית Properties.
// Deletes all user properties. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteAllProperties();
חזרה
Properties – מאגר Properties זה, לשרשור
deleteProperty(key)
מוחק את המאפיין עם המפתח הנתון בחנות הנוכחית Properties.
// Deletes the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); userProperties.deleteProperty('nickname');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
key | String | המפתח של המאפיין שרוצים למחוק |
חזרה
Properties – מאגר Properties זה, לשרשור
getKeys()
מקבל את כל המפתחות בחנות Properties הנוכחית.
// Sets several properties, then logs the value of each key. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const keys = scriptProperties.getKeys(); Logger.log('Animals known:'); for (let i = 0; i < keys.length; i++) { Logger.log(keys[i]); }
חזרה
String[] – מערך של כל המפתחות בחנות Properties הנוכחית
getProperties()
מקבל עותק של כל צמדי ערך/מפתח בחנות הנוכחית Properties. שימו לב שהאובייקט שמוחזר הוא לא תצוגה פעילה של החנות. לכן, שינוי המאפיינים באובייקט שמוחזר לא יעדכן אותם אוטומטית באחסון, ולהפך.
// Sets several script properties, then retrieves them and logs them. const scriptProperties = PropertiesService.getScriptProperties(); scriptProperties.setProperties({ cow: 'moo', sheep: 'baa', chicken: 'cluck', }); const animalSounds = scriptProperties.getProperties(); // Logs: // A chicken goes cluck! // A cow goes moo! // A sheep goes baa! for (const kind in animalSounds) { Logger.log('A %s goes %s!', kind, animalSounds[kind]); }
חזרה
Object – עותק של כל צמדי מפתח/ערך בחנות Properties הנוכחית
getProperty(key)
מחזירה את הערך שמשויך למפתח הנתון בחנות Properties הנוכחית, או null אם לא קיים מפתח כזה.
// Gets the user property 'nickname'. const userProperties = PropertiesService.getUserProperties(); const nickname = userProperties.getProperty('nickname'); Logger.log(nickname);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
key | String | המפתח של ערך המאפיין שרוצים לאחזר |
חזרה
String – הערך שמשויך למפתח הנתון בחנות Properties הנוכחית
setProperties(properties)
מגדיר את כל צמדי מפתח/ערך מהאובייקט הנתון בחנות Properties הנוכחית.
// Sets multiple user properties at once. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
properties | Object | אובייקט שמכיל צמדים של מפתח/ערך להגדרה |
חזרה
Properties – מאגר Properties זה, לשרשור
setProperties(properties, deleteAllOthers)
מגדירה את כל צמדי מפתח/ערך מהאובייקט הנתון בחנות Properties הנוכחית,
אפשר גם למחוק את כל המאפיינים האחרים בחנות.
// Sets multiple user properties at once while deleting all other user // properties. const userProperties = PropertiesService.getUserProperties(); const newProperties = { nickname: 'Bob', region: 'US', language: 'EN' }; userProperties.setProperties(newProperties, true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
properties | Object | אובייקט שמכיל צמדים של מפתח/ערך להגדרה |
delete | Boolean | true כדי למחוק את כל שאר צמדי המפתח/ערך באובייקט properties; false כדי לא |
חזרה
Properties – מאגר Properties זה, לשרשור
setProperty(key, value)
מגדיר את צמד המפתח/ערך שצוין בחנות הנוכחית Properties.
// Sets the user property 'nickname' to 'Bobby'. const userProperties = PropertiesService.getUserProperties(); userProperties.setProperty('nickname', 'Bobby');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
key | String | המפתח של המאפיין |
value | String | הערך שרוצים לשייך למפתח |
חזרה
Properties – מאגר Properties זה, לשרשור