SPFx Tenant Properties Preview now available for First Release tenants

Microsoft

Hi All,

 

Tenant properties allow tenant administrators to add properties in the app catalog that can be read by various SharePoint Framework components. The tenant properties are managed by tenant administrators using the Microsoft SharePoint Online Management Shell which is a PowerShell module to manage your SharePoint Online subscription in the Office 365.

 

Tenant Properties is currently in preview and is available to First Release tenants. 

 

Here is the documentation on how to use the SharePoint Online Management Shell to manage properties and use the REST API to read those properties: https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tenant-properties

 

We would love to hear your feedback! Do post your comments/feedback/suggestions below!

11 Replies
The values for comments and description are interchanged at the moment. I have created an issue on github already, just wanted to warn the people reading here as well...
Thanks! Yes, this is a known issue and will be fixed soon!

What will happen if the key already exists and we run the Set-SPOStorageEntity again ? Will it be overwritten or throw error ? 

Would be amazing if we could also have something like Update-SPOStorageEntity and Delete-SPOStorageEntity  or Remove-SPOStorageEntity as well.

Also, is there any character limit to this ?
 

 

If you do set on an existing key, it will update that key if it exists with the new value.

Yes, we have Remove-SPOStorageEntity to remove keys.

I am not aware of character limitations, but can you test if you have those special characters failing?
Hi, the link to docs comes up with a 404.

Thanks! Not sure what changed but it works now. 

great to see the ever useful old 'property bag' resurface.

 

be good to see PnP JS Core encapsulate the GET request to make this neater and obviate uneeded code lines. hopefully in next release perhaps?

just been having a run through with this and the powershell side was sweet, no problem. I have checked that I can retrieve the value.

 

but am a bit stuck with setting up the right typescript code to read the value back. I don't seem to be getting any data but that may be my code is wrong. Still learning Typescript.

 Can anyone help and confirm correct coding for this basic read op? thanks hopefully.

 

  private getTenantProperty(): Promise<ITenantProperty> {
    return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/GetStorageEntity('Test1')`, SPHttpClient.configurations.v1)
      .then((response: SPHttpClientResponse) => {
       var prop = response.json();
       return prop;
      });
  }
export interface ITenantProperty{
  '@odata.null'?:boolean;
  Value:string;
  Description?:string;
  Comment?:string;
}

sorted this out in the end and is all working nicely now. Its worth noticing that no json properties are returned for a key that does not exist. so that needs checking for. I guess there is a neat way to use the @odata.null for this but I don't know how so have gone for a simpler test.

 

export interface ITenantProperty{
  '@odata.null'?:boolean;
  Value?:string;
  Description?:string;
  Comment?:string;
}

 

  private getTenantProperty(key :string):Promise<ITenantProperty>{
    if (DEBUG && Environment.type === EnvironmentType.Local) {
      Promise.resolve("LOCAL");
    }
    else{
    let prop:ITenantProperty = {Value:'fetching...'};
          return new Promise<ITenantProperty>((resolve,reject) => {
            let endpoint = Text.format("{0}/_api/web/GetStorageEntity('{1}')", this.context.pageContext.web.absoluteUrl,key);
            this.context.spHttpClient.get(endpoint, SPHttpClient.configurations.v1).then((response: SPHttpClientResponse) => {
              if(response.ok) {
                response.json().then((json:any) =>
                   if(json.Value  ===undefined){
                    prop.Comment = key + "key not found";
                   }
                   else{              
                   prop.Value = json.Value;
                   prop.Comment = json.Comment;
                   prop.Description = json.Description;
                   }
                  resolve(prop);
                })
                .catch((error) => { reject(error); });
              }
              else {
                reject(response);
              }
            })
            .catch((error) => { reject(error); }); 
           });
    }
  }

Hey @kath patterson , have added the support for this endpoint in PnP js. It will be available in the next release which will be available around December.

Do update it when it becomes available.

After that, you can use the below code in your webpart:

pnp.sp.web.getStorageEntity('SPFxTestKey').then(r => {
    console.log(r);
});

 

that's brilliant @Gautam Sheth. I am a big fan of pnp js as  a productivity tool and a way of encapsulating agile code such that it can move forward wthout breaking solutions or requiring any rework.

 

I will certainly try this out and post feedback. great job and keep going with this excellent toolset.