I'm following on from the various examples on the microsoft website for devepos extensions, but the one for creating and editing documents does not seem to work for me (https://learn.microsoft.com/en-us/azure/devops/extend/develop/data-storage?view=azure-devops)
window.requirejs.config({
enforceDefine: true,
paths: {
'SDK': './lib/SDK.min',
}
});
window.requirejs(['SDK'], function (SDK) {
if (typeof SDK !== 'undefined') {
console.log("SDK is defined. Trying to initialize...");
SDK.init();
SDK.ready().then(() => {
console.log("SDK is ready");
// Get data service
SDK.getService(SDK.getContributionId()).then(function (dataService) {
// Prepare document first
var newDoc = {
fullScreen: false,
screenWidth: 500
};
dataService.createDocument("MyCollection", newDoc).then(function (doc) {
// Even if no ID was passed to createDocument, one gets generated
console.log("Doc id: " + doc.id);
});
});
});
} else {
console.log('SDK is not defined');
}
});
After calling SDK.getService, dataService is always undefined. As far as I can tell, the SDK has initialised correctly because many of the other SDK functions seem to work as expected, and the contributionID is correct. But I don't want to rule that out as a cause since I had a lot of trouble getting rid of the 'No handler found on any channel for message:' error.
Any help or suggestions is much appreciated.
I noticed some others had the similar issue with dataService
. There is a repo which seems to be working. Hope it's helpful for you.
private async initializeState(): Promise<void> {
await SDK.ready();
const accessToken = await SDK.getAccessToken();
const extDataService = await SDK.getService<IExtensionDataService>(CommonServiceIds.ExtensionDataService);
this._dataManager = await extDataService.getExtensionDataManager(SDK.getExtensionContext().id, accessToken);
this._dataManager.getValue<string>("test-id").then((data) => {
this.setState({
dataText: data,
persistedText: data,
ready: true
});
}, () => {
this.setState({
dataText: "",
ready: true
});
});
}