2/25/2017

Getting List's Incoming Email Settings From JavaScript

This task may be pretty unique but on one of the project I needed to get Incoming Email settings for all document libraries using JavaScript only.
After brief investigation I found that there are no any related properties in CSOM's/JSOM's List object.
But you can alway get list's Schema XML and get practically any information from there. Needed property is stored as attribute and has name EmailAlias.
So, the solution was pretty simple:
// getting context
var ctx = SP.ClientContext.get_current();
// getting web
var web = ctx.get_web();
// getting list
var list = web.get_lists().getByTitle('Some Title');
// loading SchemaXml
ctx.load(list, 'SchemaXml');
ctx.executeQueryAsync(function() {
  // needed property is stored as an attribute with name EmailAlias
  // if the property is not empty then Incoming Email is configured for the list
  var content = (new window.DOMParser()).parseFromString(list.get_schemaXml(), 'text/xml');
  var emailAlias = content.getElementsByTagName('List')[0].getAttribute('EmailAlias');
});

Using this approach you can also get other properties as well. Some of them are also included in JSOM's object as properties but some may not.

Have fun!

No comments:

Post a Comment