gpt4 book ai didi

javascript - 适用于工作流的 SharePoint JavaScript API 引发错误

转载 作者:行者123 更新时间:2023-11-29 10:40:01 25 4
gpt4 key购买 nike

我正在尝试访问有关在 SharePoint 列表中运行工作流的信息,但我遇到了工作流服务 JSOM 库的问题。我正在使用工作流服务,就像我能找到的每个示例一样,请参见下面的代码:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var servicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var instanceService = servicesManager.getWorkflowInstanceService();

执行代码时,上面代码片段的最后一行抛出异常

TypeError: this.get_context is not a function.

最佳答案

可能会发生此错误,因为尚未加载 SharePoint JavaScript 库中的指定文件之一。

  • SP.js
  • SP.Runtime.js
  • SP.WorkflowServices.js

为确保已加载指定文件,您可以考虑以下方法:

SP.SOD.registerSod('SP.ClientContext', SP.Utilities.Utility.getLayoutsPageUrl('sp.js'));
SP.SOD.registerSod('SP.WorkflowServices.WorkflowServicesManager', SP.Utilities.Utility.getLayoutsPageUrl('SP.WorkflowServices.js'));
SP.SOD.loadMultiple(['SP.ClientContext', 'SP.WorkflowServices.WorkflowServicesManager'], function(){

var ctx = SP.ClientContext.get_current();
var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web());
var workflowSubscriptionService = workflowServicesManager.getWorkflowSubscriptionService();
//...

});

SP.SOD.loadMultiple function is intended for loading on demand scripts which in turn is a part of SharePoint JavaScript Library. Alternatively you could utilize jQuery.getScript() from jQuery library.

关于javascript - 适用于工作流的 SharePoint JavaScript API 引发错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30940364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com