locked
"Save Conflict" Error In workflow RRS feed

  • Question

  • Hi,

    on the new item created workflow will insiated . on that time i have pick the item value n update anothe filde on same item on that time i get error "Save Conflict"

     

    Error:

    Microsoft.SharePoint.SPException was caught
      Message=Save Conflict

    Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
      Source=Microsoft.SharePoint
      ErrorCode=-2130575305
      StackTrace:
           at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
           at Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents)
           at Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents)
           at Microsoft.SharePoint.SPListItem.Update()
           at HR4UWorkFlow.HR4UWFlow.GrantPermission(SPListItem CurrentListItem, SPWeb oSPWeb, SPRoleType SPRoleType, SPPrincipal SPPrincipal)
      InnerException: System.Runtime.InteropServices.COMException
           Message=Save Conflict

    Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
           Source=""
           ErrorCode=-2130575305
           StackTrace:
                at Microsoft.SharePoint.Library.SPRequestInternalClass.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
                at Microsoft.SharePoint.Library.SPRequest.AddOrUpdateItem(String bstrUrl, String bstrListName, Boolean bAdd, Boolean bSystemUpdate, Boolean bPreserveItemVersion, Boolean bUpdateNoVersion, Int32& plID, String& pbstrGuid, Guid pbstrNewDocId, Boolean bHasNewDocId, String bstrVersion, Object& pvarAttachmentNames, Object& pvarAttachmentContents, Object& pvarProperties, Boolean bCheckOut, Boolean bCheckin, Boolean bMigration, Boolean bPublish)
           InnerException:

    Can i know what i am doing rong.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Monday, December 26, 2011 8:14 AM

Answers

  • Hi, I got the solution. what the exact problem ocuring is i have using event handler on updated time on updateing tim ei also usse update list item so simultaniusly work flow and event handle is working . so i get thee error of save conflict. but still i have no clue to how to handle if both(event handler and work flow) are executing same time so how handle both suscessfully.
    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Tuesday, December 27, 2011 6:27 AM

All replies

  • In initialworkflow method you are trying to update the same item using Item.Update(), Try to use Item.SystemUpdate()

    Please let me know if this resolve your issue.

    Monday, December 26, 2011 9:03 AM
  • i also usse Item.SystemUpdate()

    but same problem exist.


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Monday, December 26, 2011 9:48 AM
  • Is that same code which you have Posted on the below forum,

    http://social.msdn.microsoft.com/Forums/en-US/sharepointadmin/thread/2d391c8f-0e15-4345-bfb7-e4715c6c2abe

    if yes then I can see two times you have used the MyListItem.Update(). Instead can give you try using MyListItem.SystemUpdate().

    Also I am hoping only one assembly is present in the GAC for the workflow.

     

    Monday, December 26, 2011 10:07 AM
  • its old code.. and also i have updating two time same list in same methode.
    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Monday, December 26, 2011 10:34 AM
  • Code is below
    
    
    
    private void Execute(object sender, EventArgs e)
    
    {
    
    workflowProperties.Workflow.CreateHistoryEvent((int)SPWorkflowHistoryEventType.TaskCreated, 0, workflowProperties.OriginatorUser, string.Empty, "Workflow has been start Execution Event", string.Empty);
    
    string Emp = workflowProperties.OriginatorUser.LoginName;
    
    string[] strSplitCureentLoginEmpID = Emp.Split('\\');
    
    string LoginEmpID = strSplitCureentLoginEmpID[1].ToString();
    
    string Subject = string.Empty;
    
    string MessageBody = string.Empty;
    
    string FromAddress = string.Empty;
    
    SPSecurity.RunWithElevatedPrivileges(delegate()
    
    {
    
    using (SPSite site = new SPSite(workflowProperties.List.Lists.Web.Url))
    
    {
    
    using (SPWeb web = site.OpenWeb())
    
    {
    
    SPList myList = web.Lists[workflowProperties.List.Title];
    
    SPListItem myListItem = myList.Items.GetItemById(workflowProperties.ItemId);
    
    if (null != myListItem)
    
    {
    
    if (null != myListItem["Location"] && myListItem["Category"].ToString().Length > 0)
    
    {
    
    web.AllowUnsafeUpdates = false;
    
    string Location = myListItem["Location"].ToString();
    
    string Catagory = myListItem["Category"].ToString();
    
    SPList listPDBoard = web.Lists["HR_Category_List"];
    
    SPQuery spquery = new SPQuery();
    
    spquery.Query = "<Where>" +
    
    "<And>" +
    
    "<Eq>" +
    
    "<FieldRef Name='Category' />" +
    
    "<Value Type='Choice'>" + Catagory + "</Value>" +
    
    "</Eq>" +
    
    "<Eq>" +
    
    "<FieldRef Name='Location' />" +
    
    "<Value Type='Choice'>" + Location + "</Value>" +
    
    "</Eq>" +
    
    "</And>" +
    
    "</Where>";
    
    SPListItemCollection items = listPDBoard.GetItems(spquery);
    
    SPUser siteUser;
    
    SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
    
    if (items.Count > 0)
    
    {
    
    foreach (SPListItem listitem in items)
    
    {
    
    web.AllowUnsafeUpdates = true;
    
    string AssignTo = listitem["Assigned To"].ToString();
    
    string Escalation1 = listitem["Escalation1"].ToString();
    
    string Escalation2 = listitem["Escalation2"].ToString();
    
    string location = listitem["Location"].ToString();
    
    if (null != listitem["Assigned To"] && listitem["Assigned To"].ToString().Length > 0)
    
    {
    
    SPFieldUserValueCollection oUser_AssignedTo = MyChoice.Shared.MyChoiceUtility.GetUsers(listitem, listitem.Fields["Assigned To"]);// GetSingleUser(listitemProjectDashBoard, listitemProjectDashBoard["Business Lead"].ToString());
    
    foreach (SPFieldUserValue userValue in oUser_AssignedTo)
    
    {
    
    siteUser = userValue.User;
    
     
    
    SPFieldUserValue UserName = new SPFieldUserValue(web, siteUser.ID, siteUser.LoginName);
    
    UserCollection.Add(UserName);
    
    }
    
    myListItem["Assigned to"] = UserCollection;
    
    UserCollection.Clear();
    
    }
    
    if (null != listitem["Escalation1"] && listitem["Escalation1"].ToString().Length > 0)
    
    {
    
    SPFieldUserValueCollection oUser_AssignedTo = MyChoice.Shared.MyChoiceUtility.GetUsers(listitem, listitem.Fields["Escalation1"]);// GetSingleUser(listitemProjectDashBoard, listitemProjectDashBoard["Business Lead"].ToString());
    
    foreach (SPFieldUserValue userValue in oUser_AssignedTo)
    
    {
    
    siteUser = userValue.User;
    
    SPFieldUserValue UserName = new SPFieldUserValue(web, siteUser.ID, siteUser.LoginName);
    
    UserCollection.Add(UserName);
    
    //Assigned_x0020_to
    
    }
    
    myListItem["Escalation-1 Name"] = UserCollection;
    
    UserCollection.Clear();
    
    }
    
    if (null != listitem["Escalation2"] && listitem["Escalation2"].ToString().Length > 0)
    
    {
    
    SPFieldUserValueCollection oUser_AssignedTo = MyChoice.Shared.MyChoiceUtility.GetUsers(listitem, listitem.Fields["Escalation2"]);// GetSingleUser(listitemProjectDashBoard, listitemProjectDashBoard["Business Lead"].ToString());
    
    foreach (SPFieldUserValue userValue in oUser_AssignedTo)
    
    {
    
    siteUser = userValue.User;
    
    SPFieldUserValue UserName = new SPFieldUserValue(web, siteUser.ID, siteUser.LoginName);
    
    UserCollection.Add(UserName);
    
    //Assigned_x0020_to
    
    }
    
    myListItem["Escalation-2 Name"] = UserCollection;
    
    UserCollection.Clear();
    
    }
    
    //myListItem["Description"] = "hasan jamal siddiqui";
    
    myListItem["Employee ID"] = LoginEmpID;
    
     
    
     
    
    // fill the number of holidays based upon the location.
    
    List<DateTime> lstHRHolidayCollection = HolidayList(location);
    
    DateTime oTodayDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy,MM,dd"));
    
    // DateTime ActiveDueDate = Convert.ToDateTime(listitem["Due Date"]);
    
    int intNoOfDueDays = countNoOfDueDays();
    
    DateTime ActiveDueDate = oTodayDate.AddDays(intNoOfDueDays);
    
    DateTime CreateDate = Convert.ToDateTime(myListItem["Created"]);
    
    // int intNoOfBusinessDays = MyChoiceDateTime.GetFullWorkingDaysBetween(oTodayDate, ActiveDueDate, lstHRHolidayCollection);
    
    DateTime DueDateNext = MyChoice.Shared.MyChoiceDateTime.NextWorkingDay(CreateDate, intNoOfDueDays, lstHRHolidayCollection);
    
    myListItem["Due Date"] = DueDateNext;
    
    myListItem["blnUpdatedWF"] = true;
    
     
    
    // give permission to 'Assigned to'
    
    SPUser oUser = workflowProperties.Web.EnsureUser(myListItem["Assigned to"].ToString().Split('#')[1]);
    
    GrantPermission(myListItem, workflowProperties.Web, SPRoleType.Contributor, oUser);
    
    SPGroup oPMSHrGrp = workflowProperties.Web.Groups["Super HR"];
    
    GrantPermission(myListItem, workflowProperties.Web, SPRoleType.Administrator, oPMSHrGrp);
    
    SPUser oCreatedBy = workflowProperties.Web.EnsureUser(myListItem["Created By"].ToString().Split('#')[1]);
    
    //SPGroup oPMHrGrp = workflowProperties.Web.Groups["Hr "];
    
    GrantPermission(myListItem, workflowProperties.Web, SPRoleType.Administrator, oCreatedBy);
    
    SPUser oUserEscalation1 = workflowProperties.Web.EnsureUser(Escalation1.ToString().Split('#')[1]);
    
    GrantPermission(myListItem, workflowProperties.Web, SPRoleType.Reader, oUserEscalation1);
    
    SPUser oUserEscalation2 = workflowProperties.Web.EnsureUser(Escalation2.ToString().Split('#')[1]);
    
    GrantPermission(myListItem, workflowProperties.Web, SPRoleType.Reader, oUserEscalation2);
    
    
    myListItem.Update();
    
    web.AllowUnsafeUpdates = false;
    
    StatusOpen();
    
     
    
    
     
    
     
    
    }
    
    }
    
    }
    
    }
    
    }
    
    }
    
    });
    
     
    
    }
    


    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Monday, December 26, 2011 10:37 AM
  • Hi, call the myList.Update() method after the  myListItem.Update(); see below as per your code reference,

    ;;;

    myListItem.Update();
    myList.Update()
    

    ;;;;


    anil, Mark as Answer if it helps..
    Monday, December 26, 2011 10:55 AM
  • Hi, I got the solution. what the exact problem ocuring is i have using event handler on updated time on updateing tim ei also usse update list item so simultaniusly work flow and event handle is working . so i get thee error of save conflict. but still i have no clue to how to handle if both(event handler and work flow) are executing same time so how handle both suscessfully.
    Hasan Jamal Siddiqui(MCTS),Share Point Application Developer,TCS
    Tuesday, December 27, 2011 6:27 AM
  • Hi,

          The workflow will be instantiated when the item will be added or item will be updated. Since the workflow is being instantiated when the item is being updated by the workflow (as you are facing the save issue). Try to set the workflow to be instantiated when the item is added not the updated and check for the issue.

     

    Please let me know if it helps!!!! 


    Ajeet
    Tuesday, December 27, 2011 7:20 AM