0

I'm using @pnp in my SPFX project, and I need to get tenant property. The code is as followed:

sp.web.getStorageEntity('mytenantproperty1')
      .then((prop: StorageEntity) => {
    //How do I handle odata.null?
      return prop.value;
});

If the key doesn't exist the results I get back is

Object {odata.metadata: "https://_________.sharepoint.com/sites/ASite/_a…", odata.null: true} odata.metadata:"https://________.sharepoint.com/sites/ASite/_api/$metadata#Edm.Null" odata.null:true proto:Object {constructor: , defineGetter: , defineSetter: , …}

I've tried to check odata.null value but it doesn't appear to be there. So how do I check for invalid key?

0

You can check odata.null in the prop object itself.

Using this snippet you can check for invalid key:

sp.web.getStorageEntity('mytenantproperty1')
      .then((prop: StorageEntity) => {

        console.log(prop);

        if(prop["odata.null"]){
          // storage entity doesnt exist

          // do something (like create entity or return empty string)
          return "";
        }

        // storage entity exists, return its value
        return prop.Value;
});
  • 1
    Thank you. These documentations always shows the happy path, but never how to handle issues. – Cann0nF0dder Aug 14 '18 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.