locked
How to programatically check on the initiation form whether workflow is running or completed and display some message RRS feed

  • Question

  • I have a Sequential workflow in Sharepoint 2010 with an Initiation form. I want this workflow to do a check whether an approval workflow is already running on the same document when I click the start workflow button and if its running it should display a message. Does anyone know how I can implement this or any similar scenario?
    Friday, February 17, 2012 7:56 AM

Answers

  • Hi Osee,

    In your project, add a InitiationForm item, then in page_load event, add the code as below to determine if the workflow is running.

    protected void Page_Load(object sender, EventArgs e)
            {
                InitializeParams();
    
                // Optionally, add code here to pre-populate your form fields.
    
              
    
    
                foreach (SPWorkflow workflow in workflowListItem.Workflows)
                { 
                    //Determine if the workflow called "ApprovalWF" is running.
                    if (workflow.ParentAssociation.Name == "ApprovalWF" && workflow.InternalState == SPWorkflowState.Running)
                    {
                        TextBox1.Text = "RUNNING";
                    }
                } 
    
            }
    

    Thanks,
    Simon      



    Simon Huang

    TechNet Community Support

    • Marked as answer by Shimin Huang Friday, February 24, 2012 5:26 AM
    Wednesday, February 22, 2012 7:04 AM

All replies

  • You can try the following code:

    http://geekswithblogs.net/dotnetrodent/archive/2008/08/13/124408.aspx


    Varun Malhotra
    =================
    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

    • Proposed as answer by ddpatil Friday, February 17, 2012 9:23 AM
    Friday, February 17, 2012 8:39 AM
  • Hi Osee,

    In your project, add a InitiationForm item, then in page_load event, add the code as below to determine if the workflow is running.

    protected void Page_Load(object sender, EventArgs e)
            {
                InitializeParams();
    
                // Optionally, add code here to pre-populate your form fields.
    
              
    
    
                foreach (SPWorkflow workflow in workflowListItem.Workflows)
                { 
                    //Determine if the workflow called "ApprovalWF" is running.
                    if (workflow.ParentAssociation.Name == "ApprovalWF" && workflow.InternalState == SPWorkflowState.Running)
                    {
                        TextBox1.Text = "RUNNING";
                    }
                } 
    
            }
    

    Thanks,
    Simon      



    Simon Huang

    TechNet Community Support

    • Marked as answer by Shimin Huang Friday, February 24, 2012 5:26 AM
    Wednesday, February 22, 2012 7:04 AM