속성 객체는 사용자, 문서 또는 스크립트 속성에 액세스하는 인터페이스 역할을 합니다. 특정 속성 유형은 스크립트가 호출한 PropertiesService의 세 가지 메서드(PropertiesService.getDocumentProperties(), PropertiesService.getUserProperties() 또는 PropertiesService.getScriptProperties()) 중 어떤 메서드에 따라 달라집니다.
속성은 스크립트 간에 공유할 수 없습니다. 속성 유형에 관한 자세한 내용은
속성 서비스 가이드를 참고하세요.
메서드
| 메서드 | 반환 유형 | 간략한 설명 |
|---|---|---|
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 속성
객체의 다른 모든 키-값 쌍을 삭제하려면, 삭제하지 않으려면 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 저장소(연결용)