I'm trying to retrieve a setting within a document which I have previously saved within the same session, however i'm getting settings.getItem is not a function
.
I'm attempting to do this via an Word Online session within Chrome, and have been referring to the documentation here, and have also seen this post (but I don't think it fits my specific problem)
As mentioned, saving the setting works fine and when I download the file I can see the setting has been saved.
I'm using react + redux for this, so the snippet below is from the redux action creator:
export function getSetting() {
//this function tries to find a setting within the document
return function(dispatch, getState) {
window.Word.run(
function(context) {
let settings = Office.context.document.settings
var thisSetting
try {
console.log('attempting to find existing setting for ' + constants.ORG_ID)
thisSetting = settings.getItem(constants.ORG_ID)
console.log('got ' + thisSetting.value)
context.load(thisSetting)
} catch (error) {
thisSetting = null
console.log('couldn\'t find setting)
console.log(error.message)
}
return context.sync()
.then(
function() {
if (thisSetting) {
dispatch(requestSetThisSetting (thisSetting.value))
console.log('got setting ' + thisSetting.value)
}
}
)
}
)
}
}
Any ideas on how I can successfully retrieve settings?
Updated code based on answer (below)
I've updated this post with working code based on the answer provided by Rick and Juan (thanks guys!)
export function getSetting() {
//this function tries to find a setting within the document
return function(dispatch, getState) {
let currentSetting = Office.context.document.settings.get(constants.ORG_ID)
console.log('current setting is ' + currentSetting)
if (currentSetting) dispatch(requestSetSetting(currentSetting))
}
}