Get distribution list from Outlook via JavaScript

In Outlook, I have 7 Groups where my email id. I need to get the group names (only name of the group not members of the group) where my email id. Group Names are: “Team A”, “Team B” etc. Currently I can get group count.

var theMailItem = outLookApp.CreateItem(0);
//Count number of groups: which returns me 7
var test = theMailItem.Session.CurrentUser.AddressEntry.GetExchangeUser.GetMemberOfList.Count;
for (var i = 0; i < test; i++) {
   alert(test[i].Name);
}

Above code always return null. I want only 7 groups names like “Team A”, “Team B” etc.

Answer

Firstly, all collections in OOM are 1 based, not 0.

Secondly, your “test” variable is an int, so test[i] makes no sense.

Thirdly, you can use a much simpler loop:

var dl = outLookApp.Session.CurrentUser.AddressEntry.GetExchangeUser().GetMemberOfList();
for (var i = 1 ; i < dl.count; i++)
{
   alert(dl.Item(i + 1).Name);
}