SharePoint 通过各种对象触发工作流

  前言

  真的是好久好久之前存的草稿了,当时只保存了代码,大家看看还有用不,哈哈

  正文

  通过JavaScript去触发列表工作流,代码如下:

复制代码
function startWF(itemID, listId) {
    var context = SP.ClientContext.get_current();
    var web = context.get_web();
    var workflowServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
    var workflowSubscriptionService = workflowServiceManager.GetWorkflowSubscriptionService();
    var subscriptions = workflowSubscriptionService.EnumerateSubscriptionsByList(listId);
    //run all workflows associated with the list
    context.load(subscription);
    context.executeQueryAsync(function(sender, args) {
        foreach(var workflowSubscription in subscriptions) {
            var inputParameters = {};
            workflowServiceManager.GetWorkflowInstanceService().StartWorkflowOnListItem(workflowSubscription, itemId, inputParameters);
        }
        context.executeQueryAsync(Function.createDelegate(this, this.onStartSucceeded), Function.createDelegate(this, this.onStartFailed));
    },
    Function.createDelegate(this, this.onLoadFailed));

}

function onStartSucceeded(sender, args) {
    alert("Workflow Started Successfully.");
}

function onStartFailed(sender, args) {
    alert('Workflow Initiation Failed  ' + args.get_message() + '\n' + args.get_stackTrace());
}

function onLoadFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
复制代码

  代码二,启动站点工作流,如下:

复制代码
function LoadScripts() {
    SP.SOD.executeFunc("sp.js", "SP.ClientContext",
    function() {
        SP.SOD.registerSod('sp.workflowservices.js', SP.Utilities.Utility.getLayoutsPageUrl('sp.workflowservices.js'));
        SP.SOD.executeFunc('sp.workflowservices.js', "SP.WorkflowServices.WorkflowServicesManager", StartSiteWorkflow);
    })
}

function StartSiteWorkflow() {

    var context = SP.ClientContext.get_current();

    var web = context.get_web();

    //Workflow Services Manager
    var wfServicesManager = new SP.WorkflowServices.WorkflowServicesManager(context, web);

    //Workflow Interop Service used to interact with SharePoint 2010 Engine Workflows
    var interopService = wfServicesManager.getWorkflowInteropService()

    //Initiation Parameters have to be in a plain JS Object.
    var initiationParameters = {
        FirstName: "Vardhaman",
        LastName: "Deshpande"
    };

    //Start the Site Workflow by Passing the name of the Workflow and the initiation Parameters.
    interopService.startWorkflow("My Workflow", null, null, null, initiationParameters);

    context.executeQueryAsync(function() {
        console.log("workflow started");
    },
    function(sender, args) {
        console.log(args.get_message());
    });
}

jQuery(document).ready(function() {
    LoadScripts();
});
复制代码

  代码三,通过PowerShell去启动列表工作流

复制代码
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$sourceWebURL = 'http://devserver'
$TargetWorkflow = 'AutoUpdateAppointmentStatus'
$spSourceWeb = Get-SPWeb $sourceWebURL
$spSourceList = $spSourceWeb.Lists['ServiceAppointments']
$wfm = New-object Microsoft.SharePoint.WorkflowServices.WorkflowServicesManager($spSourceweb)
$sub = $wfm.GetWorkflowSubscriptionService()
$WF = $sub.EnumerateSubscriptionsByList($spSourcelist.ID) | Where-Object {$_.Name -eq "$TargetWorkflow"}
$wfis = $wfm.GetWorkflowInstanceService()
$object = New-Object 'system.collections.generic.dictionary[string,object]'
$object.Add("itemId", 42);
$object.Add("WorkflowStart", "StartWorkflow");
$wfis.StartWorkflowOnListItem($WF, 42, $object)
复制代码

  第四部分,通过CSOM操作工作流,自己只收藏了文档连接,大家看一看吧

https://docs.microsoft.com/en-us/sharepoint/dev/general-development/working-with-the-sharepoint-workflow-services-client-side-object-model

  结束语

 

  真的是好久之前的代码了,应该是之前研究工作流,保存的。

  大家可以试试,自己肯定也是觉得靠谱,才保存在博客草稿的~

posted @   霖雨  阅读(92)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2020-03-08 SharePoint Online 工作流添加历史记录
点击右上角即可分享
微信分享提示