0

I don't have access to InfoPath.

I am making a custom web part with a basic form having 4 fields and a submit button. I want to start a workflow when user presses submit button? Can I do this in my custom form? I mean running some workflow on button click?

1

You can start a workflow programmatically with the code from here

private SPWorkflowAssociation GetWorkflowAssociationByName(SPListItem item, string workflowAssociationName) 
{ 
    return item.ContentType.WorkflowAssociations.GetAssociationByName(workflowAssociationName, new System.Globalization.CultureInfo("en-US")); 

} 

public void StartWorkflow(SPListItem item, string associationName) 
{ 
  try
   {                 
//get workflow association object
workflowAssociation = GetWorkflowAssociationByName(item, associationName);                 

if (workflowAssociation == null)
  throw new Exception(string.Format  ("Workflow association '{0}' could not be found in the list '{1}'", workflowAssociationName, item.ParentList.Title)); 

//start your workflow...
item.Web.Site.WorkflowManager.StartWorkflow(item, workflowAssociation, workflowAssociation.AssociationData); 
   }             
   catch (SPException spEx) 
   { //log your exception } 
} 

//that kicks off a associated workflow.
StartWorkflow(anInstanceOfSPListItem, "Masood - Approval workflow")
| improve this answer | |
  • Great! What if I want to write my own workflow? – Frank Martin Oct 28 '14 at 9:26
  • You can use SharePoint designer or visual studio. – Choggo Oct 28 '14 at 9:41
0

Look the SPWorkflowManager class. It is available from SPSite.WorkflowManager property. It has StartWorkflow methods to run new workflow instance.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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