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 working on State Machine Workflow using Visual Studio 2010 Workflow.

I want to update the list item on item changed. But unable to update the item. I am updating the item in nested If-Else condition. I am using Declarative Rule Condition.

Please Refer the code below and Workflow Image:

private void onManagerTaskChanged_Invoked(object sender, ExternalDataEventArgs e)
    {
        try
        {

            if (onManagerTaskChanged_AfterProperties1.ExtendedProperties[workflowProperties.TaskList.Fields["Status"].Id].ToString().Trim().ToUpper() == "SENT FOR CORRECTION")
            {


            }
            else if (onManagerTaskChanged.AfterProperties.ExtendedProperties[workflowProperties.TaskList.Fields["Status"].Id].ToString().Trim().ToUpper() == "APPROVED")
            {
                if (workflowProperties.Item["Planning Status"].ToString().Trim().ToUpper() == "IN PROGRESS" || workflowProperties.Item["Mid Review Status"].ToString().Trim().ToUpper() == "COMPLETED" && workflowProperties.Item["Final Status"].ToString().Trim().ToUpper() == "IN PROGRESS")
                {
                    //WriteLog("Condition is true.");
                    workflowProperties.Item["Planning Status"] = "Approved";
                    workflowProperties.Item.SystemUpdate();
                }
                else if (workflowProperties.Item["Mid Review Status"].ToString().Trim().ToUpper() == "IN PROGRESS")
                {
                    workflowProperties.Item["Mid Review Status"] = "Completed";
                    workflowProperties.Item.SystemUpdate();
                }
            }
            else
            {
            }

        }
        catch (Exception ex)
        {
            WriteLog(ex.ToString());
        }
    }

Workflow Error

I am unable to update the list item in Second if-else. I can update the list item in First if-Else or outside of Second if-Else.

In short I want to update "Approved" in Planning Status column but cant update.

Please help. Its very urgent.

  • Khan Abubakar
share|improve this question

1 Answer 1

up vote 0 down vote accepted

I was using if-else in wrong way. I was checking if-else in nested way like:

      if
    {
       // first if-else
    }
    else // first if-else
    {
      if
      {
          // second if-else
      }
      else // second if-else
      {
      }
    }

but actually above should be like:

if
{
   // first if-else
}
else // first if-else
{
}
if
{
    // second if-else
}
else // second if-else
{
}

In the above question I have used "Declarative code condition". but now using "code condition" and found it is working. If it will be written in "Declarative code condition" then also it will work.

share|improve this answer

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.