Last Update: 11/7/2016

ExtensionDataService

This API is in private preview and subject to change.

Provides a wrapper around the REST client for getting and saving extension setting values

Example

Visual Studio Team Services extension data service sample -- getting the data service

    // Get the data service
    VSS.getService(VSS.ServiceIds.ExtensionData).then(function(dataService) {
        // Set a user-scoped preference
        dataService.setValue("pref1", 12345, {scopeType: "User"}).then(function(value) {
            console.log("User preference value is " + value);
        });     
        // Get an account-scoped document in a collection
        dataService.getDocument("MyCollection", "SomeDocumentId").then(function(doc) {
            console.log("Document is " + JSON.stringify(doc, null, 2));
        });
    });

See store and manage data to learn more about storing user preferences and collections of documents.

Methods

getServiceInstance()

Factory method for creating/getting an instance of the extension settings service.

Syntax

 ExtensionDataService getServiceInstance(publisherName, extensionName, registrationId, webContext)

Parameters

Returns

getValue()

Returns a promise for retrieving a setting at the provided key and scope

Syntax

 IPromise<T> getValue(key, documentOptions)

Parameters

Returns

setValue()

Returns a promise for saving a setting at the provided key and scope

Syntax

 IPromise<T> setValue(key, value, documentOptions)

Parameters

Returns

getDocument()

Returns a promise for getting a document with the provided ID in the provided collection

Syntax

 IPromise<any> getDocument(collectionName, id, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • id: string. The ID of the document in the collection
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

getDocuments()

Returns a promise for getting all of the documents in the provided collection

Syntax

 IPromise<any[]> getDocuments(collectionName, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

createDocument()

Returns a promise for creating a document in the provided collection

Syntax

 IPromise<any> createDocument(collectionName, doc, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • doc: any. The document to store
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

setDocument()

Returns a promise for setting a document in the provided collection Creates the document if it does not exist, otherwise updates the existing document with the ID provided

Syntax

 IPromise<any> setDocument(collectionName, doc, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • doc: any. The document to store
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

updateDocument()

Returns a promise for updating a document in the provided collection A document with the ID provided must exist

Syntax

 IPromise<any> updateDocument(collectionName, doc, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • doc: any. The document to store
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

deleteDocument()

Returns a promise for deleting the document at the provided scope, collection and id

Syntax

 IPromise<void> deleteDocument(collectionName, id, documentOptions)

Parameters

  • collectionName: string. The name of the collection where the document lives
  • id: string. The ID of the document in the collection
  • documentOptions: IDocumentOptions. Optional. The scope in which the value is stored - default value is account-wide

Returns

queryCollectionNames()

Returns a promise for querying a set of collections

Syntax

 IPromise<ExtensionManagement_Contracts.ExtensionDataCollection[]> queryCollectionNames(collectionNames)

Parameters

  • collectionNames: string[].

Returns

  • IPromise<ExtensionManagement_Contracts.ExtensionDataCollection[]>

queryCollections()

Returns a promise for querying a set of collections

Syntax

 IPromise<ExtensionManagement_Contracts.ExtensionDataCollection[]> queryCollections(collections)

Parameters

  • collections: ExtensionManagement_Contracts.ExtensionDataCollection[]. The list of collections to query. Each collection will contain its collectionName, scopeType, and scopeValue

Returns

  • IPromise<ExtensionManagement_Contracts.ExtensionDataCollection[]>