1

i have found solutions where i can start list workflow on item knowking the workflow subscription ID using following lines

var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(context, web);
var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription(subID); 

After loading the subscription object, wf can be started as follows

wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, inputParameters);  

This works just fine, the problem i ran into is, that while developing the workflow, its subscription id may change (depending on how you develope it - Visual Studio/Sharepoint designer/sideload/app catalog etc.). This means harcoding the subscription id is a risk - you have to remember that every deployment the subscription id may differ, not even speaking the id is always different on production and development environment.

The question is, is there a way to start workflow by its name or in some other way so that i don't have to hardcode the subscription id?

Thanks in advance

2 Answers 2

0

Checkout this library (works well on SP online) :

https://gist.github.com/balony88/9fad769b9daaad8829d6ffa63828e18f

0

In on Premise envirement, it would be like this. It should work the same way in online.

public static bool StartWorkflow(SPListItem item, string workflowname)
    {
        SPWorkflow wkfInstance = null;

        SPWorkflowAssociation wkfAssociation = item.ContentType.WorkflowAssociations.GetAssociationByName(workflowname, CultureInfo.InvariantCulture);

        if (wkfAssociation != null)
        {
            wkfInstance = item.ParentList.ParentWeb.Site.WorkflowManager.StartWorkflow(item, wkfAssociation, "<data />");
        }
        return (wkfInstance != null);
    }

Your Answer

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

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