Update ActivityInstanceDestination

  • 29 February 2012
  • 2 replies
  • 1 view

Badge

Hi There,


 


I've got some data patching to be done, because initially due to wrong User Inputs and because the work flow had some issues, the InfoPath has saved the wrong set of values into the DB.


 


I have the following code:


 


foreach (WorklistItem worklistItem in connection.OpenWorklist())


                {


                    // open the worklist item


                    worklistItem.Open();


 


                    // match with the workflow serial number


                    if (worklistItem != null && worklistItem.SerialNumber == _wfSerialNumber)


                    {


                        // retrieve xml field - value and write the name and value to the console


                        string xmlField = worklistItem.ProcessInstance.XmlFields[0].Value;


                        xmlField = xmlField.Replace("<my:DeclineFrom>I</my:DeclineFrom>", "<my:DeclineFrom>VI</my:DeclineFrom>");


                        xmlField = xmlField.Replace("<my:InitiatorDetailsName>Sharepoint Setup</my:InitiatorDetailsName>", "<my:InitiatorDetailsName>Tester</my:InitiatorDetailsName>");


                        xmlField = xmlField.Replace("<my:InitiatorDetailsDepartment/>", "<my:InitiatorDetailsDepartment>Dept</my:InitiatorDetailsDepartment>");


                        xmlField = xmlField.Replace("<my:InitiatorDetailsDate>2012-02-03</my:InitiatorDetailsDate>", "<my:InitiatorDetailsDate>2012-01-12</my:InitiatorDetailsDate>");


                        worklistItem.ProcessInstance.XmlFields[0].Value = xmlField;


 


                        string xmlFieldAID = worklistItem.ActivityInstanceDestination.XmlFields[0].Value;


                        xmlFieldAID = xmlFieldAID.Replace("<my:DeclineFrom>I</my:DeclineFrom>", "<my:DeclineFrom>VI</my:DeclineFrom>");


                        xmlFieldAID = xmlFieldAID.Replace("<my:InitiatorDetailsName>Sharepoint Setup</my:InitiatorDetailsName>", "<my:InitiatorDetailsName>Tester</my:InitiatorDetailsName>");


                        xmlFieldAID = xmlFieldAID.Replace("<my:InitiatorDetailsDepartment/>", "<my:InitiatorDetailsDepartment>Dept</my:InitiatorDetailsDepartment>");


                        xmlFieldAID = xmlField.Replace("<my:InitiatorDetailsDate>2012-02-03</my:InitiatorDetailsDate>", "<my:InitiatorDetailsDate>2012-01-12</my:InitiatorDetailsDate>");


                        worklistItem.ActivityInstanceDestination.XmlFields[0].Value = xmlFieldAID;


 


                        worklistItem.ProcessInstance.Update();


                    }


                }


 


 


I noticed that the ProcessInstance has been updated successfully. However, the ActivityInstanceDestination does not seem to get updated. I know that my code shows that I'm updating the ProcessInstance only. So how do I update ActivityInstanceDestination?


 


I'm using SharePoint 2007, K2 Blackpoint and MS InfoPath Forms.


 


Note: I've updated the workflow and migrated other workflows to the correct workflow version so I've got no issues with new forms being raised. However, because the data is wrong, migrating the workflow makes no use. I need to patch the data in DB.


2 replies

Badge +2

Hi Christopherts,

 

Not sure if you have found an answer for your question, regardless, hope the answer below helps:

 

when you call worklistItem.ProcessInstance.Update(); it will update only the process, since you are using ActivityInstanceDestination, the field will only be updated when the action for the activity is call, try the following code:

 

XmlDocument xmlDoc = new XmlDocument();
string xmlFieldAID = string.Empty;
xmlFieldAID = worklistItem.ActivityInstanceDestination.XmlFields[0].Value;

xmlDoc.LoadXml(xmlFieldAID);
XmlNode rootNode = xmlDoc.DocumentElement;
System.Xml.XmlNamespaceManager nsMgr = new System.Xml.XmlNamespaceManager(xmlDoc.NameTable);
nsMgr.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my"));

xmlDoc.SelectSingleNode("Your XML node to be updated", nsMgr).InnerText = ((TextBox)c).Text;

StringWriter strWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);
xmlDoc.WriteTo(xmlWriter);
string xmlFieldUpdated = strWriter.ToString();

// Set the updated value to Process XML field
worklistItem.ActivityInstanceDestination.XmlFields[0].Value = xmlFieldUpdated;

worklistItem.Actions["The action for the activity"].Execute();

HTH,

 

YeeKhin

 

 

Badge

The approach suggested by  @YeeKhin should work .

 

Thanks,

Satya

Reply