20. ・サーバーに配置するScript(デモ時はコンテンツエディタで配置)
<script type="text/javascript“>
var maxId = -1; // これまでに取得したリストアイテムIDの最大値
var ListName = "PushAlerts"; // リスト表示名
var pollingInterval = 10000; // 繰り返しインターバル(On-Premisesでは大き目、Office365では小さ目が吉)
Demo③ - (1/1)
var context; var web; var list; var items; var item; var currentId; var currentTitle; var currentBody;
var itemDic = {}; var currentStatusId = "";
function startGetAllItems() {
// 定期的にリストからアイテムを取得
setInterval(function (){
items = null; itemDic = {};
context = SP.ClientContext.get_current();
web = context.get_web();
list = web.get_lists().getByTitle(ListName);
items = list.getItems(SP.CamlQuery.createAllItemsQuery()); // すみません、このあたり手抜きです(汗
context.load(items);
context.executeQueryAsync(Function.createDelegate(this, getAllItemsSuccess), null);
}, pollingInterval );
}
function getAllItemsSuccess(sender, args) {
var _maxId = 0;
var listEnumerator = items.getEnumerator();
while (listEnumerator.moveNext()) {
// 取得したアイテムをDictionaryに入れつつ最大(=最新)のIDを調査
item = listEnumerator.get_current(); ※この例では、 「Body」という名の
currentId = item.get_item("ID");
currentBody = item.get_item("Body"); 列を持つ、「PushAlerts」という名の
if(_maxId < currentId){_maxId = currentId}
}
itemDic[currentId] = currentBody リストを作成し、アイテムを追加す
if(maxId != -1 && maxId < _maxId){ ることでBoby列の内容がPush風に
// 最大のIDが前回取得時を上回っていた場合は、ステータスを更新
if(currentStatusId != "") SP.UI.Status.removeStatus(currentStatusId); 配信されます。
currentStatusId = SP.UI.Status.addStatus(itemDic[_maxId]);
} 全然PowerShellと絡めてない(汗
maxId = _maxId; // 最大のIDを保持
}
_spBodyOnLoadFunctionNames.push("startGetAllItems"); // ページ読込み時に起動
</script>
21. Resources
• SharePoint Management PowerShell Scripts
http://sharepointpsscripts.codeplex.com/
• SharePoint Server 2010 Search: Windows PowerShell cmdlets
http://social.technet.microsoft.com/wiki/contents/articles/
204.sharepoint-server-2010-search-windows-powershell-cmdlets-en-us.aspx
• Windows PowerShell compiled Help for SharePoint Server 2010
http://www.microsoft.com/download/en/details.aspx?id=7879
• The Windows PowerShell Toolbox
http://technet.microsoft.com/en-us/scriptcenter/ee861518
• Windows PowerShell Quick Reference
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=7097
• SharePoint Server 2010 向けの Windows PowerShell
http://technet.microsoft.com/ja-jp/library/ee662539.aspx
• Stsadm と Windows PowerShell 間のマッピング
http://technet.microsoft.com/ja-jp/library/ff621084.aspx
22. Communities
• PowerShellCommunity.org
http://www.powershellcommunity.org/
• PowerShell.com
– Library、 eBooks(free)、Ask the Experts
– Today’s tips
http://powershell.com/
• PowerShell Community Groups
http://powershellgroup.org/