Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am creating a custom list in Visual Studio 2010 for SharePoint 2010.

I want to set "approvement needed" for single listitems to false or disabled.

My intention is, that a element can be approved or declined just one time, but not switch from "approved" to "not approved" to "approved" and so on

More detailed scenario:

  • I've got a list of items that have to get reviewed after adding.
  • If they get approved or declined it is a absolut decision and never should be changed
  • If the item gets approved some events should be triggered
  • If it gets declined a mail should be send!

My Ideas:

Idea - Workflow:

My first idea was to create a workflow which get fired after a ListItem added. The WF should create a task that could be reviewed. If it is positive it should fire some functions and deletes itself.

Idea- Workflow Design: enter image description here

Idea- Workflow Code:

           public Guid workflowId = default(System.Guid);
                public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
                // these properties are for the workflow task that will be created.
                public SPWorkflowTaskProperties CreateTaskApproval_TaskProperties = new SPWorkflowTaskProperties();
                public SPWorkflowTaskProperties CreateTaskApproval_AffterTaskProperties = new SPWorkflowTaskProperties();
                public SPWorkflowTaskProperties CreateTaskApproval_BeforeTaskProperties = new SPWorkflowTaskProperties();
                public String CreateTaskApproval_ContentTypeId = default(System.String);
                public Int32 CreateTaskApproval_ListItemId = default(System.Int32);
                public Guid CreateTaskApproval_TaskId = default(System.Guid);

           private void createTask1_MethodInvoking(object sender, EventArgs e)
                {
                    createTask1.TaskId = new Guid();
                    // Now create the approval task.
                    // Set up some of the properties.
                    CreateTaskApproval_TaskId = Guid.NewGuid();
                    //Setting the task properties
                    CreateTaskApproval_TaskProperties.Title = "TestTitle"
                    CreateTaskApproval_TaskProperties.Description = "Description";
                    CreateTaskApproval_TaskProperties.AssignedTo = @"testemail\testuser";
                    CreateTaskApproval_TaskProperties.SendEmailNotification = false;
                    CreateTaskApproval_TaskProperties.TaskType = 1;
                    LogComment("Request Task Created.");
                }
             private void onTaskChanged1_Invoked(object sender, ExternalDataEventArgs e)
                {

    //!!!! The Problem is here at Status
                        // Check to make sure the field is there on the item.
                        if (CreateTaskApproval_TaskProperties.ExtendedProperties["Status"] != null)
                        {
                            // Evaluate the value of the field.
                            if (CreateTaskApproval_TaskProperties.ExtendedProperties["Status"].ToString() == "Approved" || CreateTaskApproval_TaskProperties.ExtendedProperties["Status"].ToString() == "Declined")
                            {

                                TaskApproval_ApproveComplete = true;
                            }
                            else
                            {
                                TaskApproval_ApproveComplete = false;
                            }
                        }
 }
                private void completeTask1_MethodInvoking(object sender, EventArgs e)
                {
                    workflowProperties.Item.ModerationInformation.Status = SPModerationStatusType.Approved;

//Fire some code here

                }

Idea - Workflow- Problems: I can't get the tasks moderation status at all. ("approved" and so on)

CreateTaskApproval_TaskProperties.ExtendedProperties["Status"]

Does any on know how to?

Idea 2 Custom ASPX Page:

An other idea is to create an aspx page that lists all elements. So the user could approve with custom acctions! What about this idea? Is it practicable and a good alternative?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

If you need to enforce that kind of logic, I would suggest either to create a workflow or implement the logic using an event handler (OnItemUpdating) on the list items for the list.

In either case you would check on the columns containing the status, and check if state is either Approved or Declined, and then (depending on your business needs) either reject any changes or just changes to that field.

share|improve this answer
    
I've edited my question on your answer! –  MOI Jul 11 '12 at 9:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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