3

I have added a custom item in ECB menu using CSOM. Now i want to start a sharepoint designer workflow on click of this custom menu item .Can anyone suggest me how to achieve this

1 Answer 1

1

Alas everytime you publish a Workflow it gets a new (GU)ID,

So starting by Workflow ID is a pain

You can start by Name (Note, this came from a button in a View, I deleted lines before pasting, so there might be typos)

event.preventDefault();
var TR = GetAncestor(this, 'TR');
var itemID = TR.id.split(',')[1];
var wfName = 'YOUR_WORKFLOW_TITLE_GOES_HERE';
SP.SOD.executeFunc('sp.workflowservices.js', 'SP.WorkflowServices.WorkflowServicesManager',
    function () {
        var ctx = new SP.ClientContext.get_current(),
            wfsManager = SP.WorkflowServices.WorkflowServicesManager.newObject(ctx, ctx.get_web()),
            wfSubs = wfsManager.getWorkflowSubscriptionService().enumerateSubscriptionsByList(_spPageContextInfo.pageListId);
        ctx.load(wfSubs);
        ctx.executeQueryAsync(function () {
            wfsEnum = wfSubs.getEnumerator();
            while (wfsEnum.moveNext()) {
                var wfSub = wfsEnum.get_current();
                if (wfSub.get_name() === wfName) {
                    wfsManager.getWorkflowInstanceService().startWorkflowOnListItem(wfSub, itemID, new Object());
                    SP.UI.Notify.addNotification('Init Workflow: ' + wfName + ' on item: ' + itemID, false);
                }
            }
        },function(e){console.error(e)});
    });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.