我按照msdn的说明通过JSOM获取WorkflowSubscriptionService。
使用SharePoint 2013 Workflow Services客户端对象模型: http://msdn.microsoft.com/en-us/library/office/dn481315(v=office.15).aspx
var clientContext = SP.ClientContext.get_current();
var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(clientContext, clientContext.get_web());
var workflowSubscriptionService = workflowServicesManager.getWorkflowSubscriptionService();
这三行总是会引发错误: TypeError:Object [object Object]没有方法' get_context' 消息:"对象[对象对象]没有方法' get_context'" 堆栈:(...) get stack:function(){[native code]} set stack:function(){[native code]} proto :错误
我找不到错误。这是一个已知的错误吗?
答案 0 :(得分:5)
由于尚未加载指定的对象,因此会发生这些错误。
要使用SharePoint 2013 Workflow Services客户端对象模型,应加载以下JSOM库:
例如,您可以使用SP.SOD.executeFunc(SharePoint JavaScript库)或jQuery.getScript()(jQuery ibrary)来确保已加载指定的文件。
示例:
var scriptbase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";
$.getScript(scriptbase + "SP.js", function () {
$.getScript(scriptbase + "SP.Runtime.js", function () {
$.getScript(scriptbase + "SP.WorkflowServices.js", function () {
var clientContext = SP.ClientContext.get_current();
var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(clientContext, clientContext.get_web());
var workflowSubscriptionService = workflowServicesManager.getWorkflowSubscriptionService();
//...
});
});
});
答案 1 :(得分:0)
确保在尝试获取上下文之前验证CSOM已加载。这是一个在SharePoint的JS加载后如何验证代码执行的示例。在这种情况下,我也记录到CSOM使用jQuery加载的div。
$(document).ready(function()
{
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function()
{
$('div#log').append("SharePoint Client Object Model Loaded<br/>");
});
});