本文讲述一个SharePoint 2013 SharePoint designer 2013 workflow开发综合实例.
在前面这篇博文里面谈到http://blog.csdn.net/abrahamcheng/article/details/8707354 SharePoint 2013 工作流开发的一些概念,笔者将在本篇以及后面几篇博客里面介绍SharePoint 2013 workflow开发综合实例,本篇先说SharePoint designer 2013 workflow开发综合实例。
准备工作:
1. SharePoint 2013 的开发环境
2. 安装SharePoint 2013 designer
3. 安装配置Workflow manager http://technet.microsoft.com/en-us/library/jj163276.aspx (注意要下面四个软件都装上)
4.安装 SharePoint server 2013 补丁 kb2817616,不装的话SharePoint 2013的Send mail action发不了邮件,说白了是微软的一个bug,在这个更新里面修了,装完后需要运行配置向导。
5. Outgoing 邮件配置
场景:
某公司内网站点有个新闻列表,需要把最新的10条新闻每天发给站点的Visitor 组。
效果(基本功能效果,没有美化,因为我只是给大家介绍可以这样用):
思路:
使用一个Site workflow来实现,是build dictionary来存储request header (指定返回数据为json格式)
使用Call HTTP Web service 调用
http://moss2013site/_api/web/lists/GetByTitle('News')/items?$select=Title,Body,ID&$top=10&$orderby=Created desc
这个action会返回一个Json数据
{"d":{"results":[{"__metadata":{"id":"408a322c-b7a4-4651-987d-17789df159d4","uri":"http:\/\/yourSharePoint2013Site\/_api\/Web\/Lists(guid'afb7bd53-c825-42ad-b149-68cf4027330b')\/Items(3)","etag":"\"1\"","type":"SP.Data.NewsListItem"},"Id":3,"Title":"Firstnews from dev home","Body":"First news from dev home body..........","ID":3},{"__metadata":{"id":"a52f1488-de17-4ff0-aa40-ea9d105be65d","uri":"http:\/\/yourSharePoint2013Site\/_api\/Web\/Lists(guid'afb7bd53-c825-42ad-b149-68cf4027330b')\/Items(4)","etag":"\"1\"","type":"SP.Data.NewsListItem"},"Id":4,"Title":"Typhoonand rainstorm in ShangHai on 08\/10\/2013","Body":"Typhoonand rainstorm in ShangHai on 08\/10\/2013 body ....","ID":4}]}}
使用json路径,取得Json中数据记录的条数
初始化mailBody:
循环Json中数据记录,拼接成邮件内容,分别用Json路径d/result[%Varible:loopIndex%]/Title, d/result[%Varible:loopIndex%]/Body, d/result[%Varible:loopIndex%]/Id取出Title, Body, Id三个字段的值,并进行拼接:
拼接格式:
拼接完成后发送邮件
因为是要每天发邮件的,因此发完邮件后使用(Pause for Duration)等待一天,再次回到第一个Stage重复每天发送邮件
整个workflow为
注意:
1. 不要使用系统帐号启动该workflow,否则可能出现措误
Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.ApplicationException: HTTP 401 The HTTP response content could not be read. 'Error while copying content to a stream.'
2. 如果Json路径不对,会出现如下错误
The DynamicValue property 'd/results(1) ' was incorrectly formatted. at Microsoft.Activities.Dynamic.DynamicValueBuilder.PathSegmentFactory.Parse
3.如果没有给Call HTTP web service设置request header,会出现如下错误:
{"error":{"code":"-1, Microsoft.SharePoint.Client.ClientServiceException","message":{"lang":"en-US","value":"The HTTP header ACCEPT is missing or its value is invalid."}}}
4. 如果loopIndex忘记自增,导致死循环,可能出现如下错误
The workflow instance exceeded the throttle of 10000 activities executed in a row and could not be unloaded because it was not persistable
或 内存溢出 memory overflow.