4

I have a list with the company name, business process and workflow initiation.

The Business Process could be Purchase Order/ Leave Request.

Workflow Initiation is a radio button which could be

Manual, On creation or On change of List Column. I want to create an approval workflow for the list and based on what is entered in the list, I want the workflow to start functioning.

The following is the code which i have used

namespace wfmaintenance.Workflow1
{
    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        public string Company;
        public string BusinessProcess;
        public string ListName;
        public string WorkflowName;
        public string WorkflowInitiation;  

        public Guid workflowId = default(System.Guid);
        public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();

        public SPWorkflowTaskProperties WfTaskProperties = new SPWorkflowTaskProperties();
        public SPWorkflowTaskProperties WfTaskBeforeProperties = new SPWorkflowTaskProperties();
        public Guid WfApproveTaskId = default(Guid);
        public int WfApproveTaskItemId;
        public bool WfApproveComplete = false;

        private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
        {
            /**  Company = workflowProperties.Item["Company"].ToString();
              BusinessProcess = workflowProperties.Item["BusinessProcess"].ToString();
              ListName = workflowProperties.Item["ListName"].ToString();
              WorkflowName = workflowProperties.Item["WorkflowName"].ToString();
              WorkflowInitiation = workflowProperties.Item[" WorkflowInitiation"].ToString();
              checkApprovalStatus();
            **/
        }

        private void notWfTaskApproved(object sender, ConditionalEventArgs e)
        {
            e.Result = !WfApproveComplete;
        }



        private void createWfTask_MethodInvoking(object sender, EventArgs e)
        {
            SPListItem currentItem = workflowProperties.Item;

            // Set up some of the properties.
            WfApproveTaskId = Guid.NewGuid();
            WfTaskProperties.Title = workflowProperties.Item["ListName"].ToString() + " is ready for review";
            WfTaskProperties.Description = "Please review and ensure it is valid.  If it is valid, then please select 'Approved' on this task and save it.";

        }

        private void onWfTaskChanged_Invoked(object sender, ExternalDataEventArgs e)
        {
            //int tid = onWfTaskChanged.AfterProperties.TaskItemId;
            SPListItem task = workflowProperties.Web.Lists["Workflow Tasks"] .GetItemById(WfApproveTaskItemId);

            SPListItem currentItem = workflowProperties.Item;

    try
    {

        if (task["Business Approval"] != null)
        {
            // Evaluate the value of the field.
                if (task["Business Approval"].ToString() == "Approved" || task["Business Approval"].ToString() == "Rejected")

                    {
                        WfApproveComplete = true;
                        task[SPBuiltInFieldId.WorkflowVersion] = 1;
                        task["Status"] = "Completed";
                        task.Update();



                    }
                    else
                    {
                        WfApproveComplete = false;

                    }
        }
        else
        {

            WfApproveComplete = false;

        }
    }
    catch (Exception ex)
    {
        WfApproveComplete = false;

    }
}

        private void completeWfTask_MethodInvoking(object sender, EventArgs e)
        {

     SPListItem task = workflowProperties.Web.Lists["Workflow Tasks"].GetItemById(WfApproveTaskItemId);

    //task[SPBuiltInFieldId.WorkflowVersion] = 1;
    //task["Status"] = "Completed";
    //task.SystemUpdate(false);


    SPListItem currentItem = workflowProperties.Item;
    if (task["Business Approval"].ToString() == "Rejected")
    {
        string ListName = workflowProperties.Item["ListName"].ToString();
        string currentTitle = workflowProperties.Item["Status"].ToString();
        workflowProperties.Item["Status"] = ListName + "is Rejected ";
        workflowProperties.Item.Update();
    }
    else
    {
        string ListName = workflowProperties.Item["ListName"].ToString();
        string currentTitle = workflowProperties.Item["Status"].ToString();
        workflowProperties.Item["Status"] =  "is Approved ";
        workflowProperties.Item.Update();
    }
        }
     }

}
  • are your approvers are entered from a peoplepicker column or a predefined spgroup- a group of spusers- within the site collection ? – userAZLogicApps Jan 7 '16 at 12:09
0

You can start from this link

There a source code of custom approval workflow that you can change for your purpose.

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.