Sometimes you need to react on item changed event and maybe you want program some application logic then. But problem is when you want to update item inside onItemChanged activity, probably you would do something like that (or maybe just I did it at first time :) )
workflowProperties.Item["Title"] = "Title was changed";
workflowProperties.Item.Update();
This particular code would seems to work fine but new onItemChange event is fired over and over. And it really isn't good solution I think. If you don't want to save just simple string like I did above. And if you want to interact with some particular changes in item, it would probably cause some mess with your application logic because of executing onItemChanged code.
You could easily use SystemUpdate() function to prevent event firing
workflowProperties.Item.SystemUpdate();
but unlucky for me it doesn't work at all.
As always there is another solution to achieve this. You can make your own Event firing class to disable event firing.
namespace CustomNamespace
{
public class EventFiringOperations : SPItemEventReceiver
{
public EventFiringOperations()
{
}
public void disableEventFiring()
{
//Obsolete way
//this.DisableEventFiring();
//Better (VS2010) (Visual studio would tell you for sure ;) )
this.EventFiringEnabled = false;
}
public void enableEventFiring()
{
//Obsolete
//this.EnableEventFiring();
//Better
this.EventFiringEnabled = false;
}
}
public class CustomClass
{
//...
EventFiringOperations eventFiring = new EventFiringOperations();
eventFiring.disableEventFiring();
item.Update(); //Now you can update :)
eventFiring.enableEventFiring();
//...
}
}
This won't help you only if you will update item inside onItemChanged activity code, but whenever you don't want to fire event when you updating item.
I have posted it here more for my benefit, but if anyone finds it useful then great.
Friday, July 22, 2011
Loop inside workflow doesn't execute a changed code
Recently I was solving this issue:
Simply I have two parallel while loops. Both use the same condition. First loop contain just onWorkflowItemChanged and second one contain code block after logToHistoryListActivity and then delayActivity.
When I deploy and run workflow everything seems work fine but when I change code at first time is used the new code (let's say I just comment part which write something to the list) but every other loop is different and and old code is executed (even I comment that part).
Simply I have two parallel while loops. Both use the same condition. First loop contain just onWorkflowItemChanged and second one contain code block after logToHistoryListActivity and then delayActivity.
When I deploy and run workflow everything seems work fine but when I change code at first time is used the new code (let's say I just comment part which write something to the list) but every other loop is different and and old code is executed (even I comment that part).
This problem takes me while to solve, but solution is very easy.
Everything what you need to do is reset time service. Here are commands to do that:
SharePoint 2007: net stop SPTimerV3 / net start SPTimerV3
SharePoint 2003: net stop SPTimer / net start SPTimer
SharePoint 2010: net stop SPTimerV4 net start SPTimerV4
The reason why old error is executed is that DelayActivity hibernates workflow and sets a new timer job. But when I changed the code the old time job was executed. That is reason why you should reset time service and "delete" old timer jobs to prevent them occurring again.
Hope this helps somebody ;)
STSADM commands to install WSP file
Everyone who works with MS SharePoint need from time to time work with WSP files. Here are some useful STSADM commands.
The location of STSADM depend on your installation, but usually you can find it here: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
-----------------------------------------
1. Add the solution
stsadm -o addsolution -filename {WSPFILENAME}
2. Deploy the solution
stsadm -o deploysolution -name {WSPFILENAME} -url {SITEURL}
3. Install the feature
stsadm -o installfeature -filename {FeatureFolder}\feature.xml
4. Activate the feature
stsadm -o activatefeature -id {FEATUREID} -url {SITEURL} -force
5. Deactive the feature
Stsadm.exe -o deactivatefeature -filename “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\{YourFeatureName}\feature.xml” -url http://servername/
6.Uninstall the feature
stsadm -o uninstallfeature -filename
7.Retract Solution
stsadm -o retractsolution -name [-url] [-allcontenturls] [-time] [-immediate]
8.Delete Solution
stsadm -o deletesolution -name
9.Upgrade Solution
stsadm -o upgradesolution -name [solutionName] -filename [fullPathToTheSolution] -immediate -allowgacdeployment
-----------------------------------------
Source:
http://littletalk.wordpress.com/2008/12/16/steps-to-install-wsp-file-in-stsadm/
For more information review:
http://technet.microsoft.com/en-us/library/cc262643(v=office.12)
The location of STSADM depend on your installation, but usually you can find it here: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
-----------------------------------------
1. Add the solution
stsadm -o addsolution -filename {WSPFILENAME}
2. Deploy the solution
stsadm -o deploysolution -name {WSPFILENAME} -url {SITEURL}
3. Install the feature
stsadm -o installfeature -filename {FeatureFolder}\feature.xml
4. Activate the feature
stsadm -o activatefeature -id {FEATUREID} -url {SITEURL} -force
5. Deactive the feature
Stsadm.exe -o deactivatefeature -filename “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\{YourFeatureName}\feature.xml” -url http://servername/
6.Uninstall the feature
stsadm -o uninstallfeature -filename
7.Retract Solution
stsadm -o retractsolution -name [-url] [-allcontenturls] [-time] [-immediate]
8.Delete Solution
stsadm -o deletesolution -name
9.Upgrade Solution
stsadm -o upgradesolution -name [solutionName] -filename [fullPathToTheSolution] -immediate -allowgacdeployment
-----------------------------------------
Source:
http://littletalk.wordpress.com/2008/12/16/steps-to-install-wsp-file-in-stsadm/
For more information review:
http://technet.microsoft.com/en-us/library/cc262643(v=office.12)
Subscribe to:
Posts (Atom)