单击按钮并使用Jsom代码终止并启动sharepoint设计器工作流以进行列表 [英] Terminate and start sharepoint designer workflows for list using Jsom code on button click
问题描述
我有一个包含自定义表单的SharePoint列表.
I have a SharePoint list which consists of custom forms.
在自定义表单中,我具有自定义按钮.
In custom forms i have custom button.
在按钮上单击我要一个接一个地终止正在运行的工作流程,并使用jsom代码启动某些工作流程.
On button click i want to terminate the running workflows one by one and start certain workflows using jsom code.
使用循环会有所帮助吗?
Using for loop will help?
我在互联网上找到了一些链接和代码,但没有任何效果.
i have found some links and code in internet but nothing works.
请举例说明.
谢谢
Poovi
推荐答案
下面的代码基于我的测试.
function terminateWorkflow(listId, itemId, subId) {
var context = SP.ClientContext.get_current();
var workflowServicesManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, context.get_web());
var workflowInstanceService = workflowServicesManager.getWorkflowInstanceService();
var wfInstances = workflowInstanceService.enumerateInstancesForListItem(listId, itemId);
context.load(wfInstances);
context.executeQueryAsync(
function (sender, args) {
var instancesEnum = wfInstances.getEnumerator();
while (instancesEnum.moveNext()) {
var instance = instancesEnum.get_current();
if (instance.get_workflowSubscriptionId().toString() == subId.toLowerCase()) {
workflowInstanceService.terminateWorkflow(instance);
context.executeQueryAsync(
function (sender, args) {
console.log("Termination Successful");
},
function (sender, args) {
console.log("Failed to terminate workflow.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
}
}
},
function (sender, args) {
console.log("Failed to load instances.");
console.log("Error: " + args.get_message() + "\n" + args.get_stackTrace());
}
);
};
参考线程.
https://sharepoint.stackexchange.com/questions/174755/how-to-stop-a-sharepoint-workflow-using- jsom
还有一个链接供您参考.
https://docs.microsoft.com/zh-cn/sharepoint/dev/general-development/working-with-the-sharepoint-workflow-services-client-side-object-model 跨度>
阅读列表项:
https://msdn.microsoft.com/zh-cn/library/office/hh185007(v = office.14).aspx
这篇关于单击按钮并使用Jsom代码终止并启动sharepoint设计器工作流以进行列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!