Pass the value from ItemUpdating to ItemUpdated

Hi All,

I need to pass a value from ItemUpdating to ItemUpdated event receiver, can anyone please suggest me how I can do it?

Regards Amit

June 16th, 2012 11:08am

Hello,

can you explain your requirement?

Can't you do all your process in the itemupdated? if you need previous value, i think you can get "beforevalues" in the itemupdated event if you declare it as "synchronous". 

<Receiver>
<Name>EventReceiver1ItemUpdated</Name>
<Type>ItemUpdated</Type>
<Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
<Class>Class.EventReceiver1.EventReceiver1</Class>
<SequenceNumber>10000</SequenceNumber>
<Synchronization>Synchronous</Synchronization>
</Receiver>

Free Windows Admin Tool Kit Click here and download it now
June 16th, 2012 11:38am

hi amit use code like bellow :

        static string test = string.Empty;
        public override void ItemUpdating(SPItemEventProperties properties)
        {
            test = "tttt";
        }
        public override void ItemUpdated(SPItemEventProperties properties)
        {
           // use test variable
        }
June 16th, 2012 12:31pm

Hi IIker,

I have already used this code however it doesn't work.

Regards Amit

Free Windows Admin Tool Kit Click here and download it now
June 16th, 2012 1:18pm

i am using codes like that, and working for me. pay attention that variable must be Static
June 16th, 2012 2:49pm

If it is static, then what about multiple requests from different users overwriting the value?
Free Windows Admin Tool Kit Click here and download it now
June 17th, 2012 12:49am

You can try using the properties argument.

link: http://sampathnarsingam.blogspot.com/2012/05/sharepoint-2010-send-notification-on.html

June 17th, 2012 12:52am

Hi Paul,

I do agree with you. Static will not work. I have gone through the link that you have provided in last reply. You have mentioned to use the properties argument however in link dummy list column (i.e. old status) is being used to pass the infomation.

Regards amit

Free Windows Admin Tool Kit Click here and download it now
June 17th, 2012 3:42am

Hello Amit,

I hope the problem is still persisting.

If the previous link is not working, i would recommend you to use Cache object to solve it.  Create a cache with key unique as listid,itemid,username.  Store the key/value with auto deletion after a particular time.  You should remember to retrieve the key in the reverse order of insertion.

Considering the problem of multiple front end servers, i should say that you can go for some distributed caching mechanisms like ncache, if necessary.

Please let us know your thoughts.

June 17th, 2012 11:29pm

Hi Paul,

That is a good suggestion. I suppose it is better to use the cache.

Regarding the multiple front end server case, i suppose both itemupdated and itemupdating will always execute on same front end server. so i should worry about the front end server case. what do you say paul?

Regards Amit

Free Windows Admin Tool Kit Click here and download it now
June 18th, 2012 4:56am

Hei Amit,

As long as both events executing in same server, you are right.


June 18th, 2012 1:20pm

Same Issue is giving in the Sandbox solution, how to pass the values between both the events. Tried many thing

1. Static Does not work

2. Before properties returns null

3. Property bag : Gives error does not work

4.HTTP caching : Give error

Please help in this issue.

Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2014 4:58am

Got the solution at last, doing to much of searching and stretching my mind :).

Well, create one column in the Main List, where values are changes  say "OLDVALUES". Set that field using the properties.ListItem["OLDVALUES"]=Value1+";" +Value2+";" +Value3+";"; in ItemUpdating event(take Value1, Values2 and Value3 using the  properties.ListItem["Value1"] and son on).

Now in Item Updating, use like string oldValue = properties.ListItem["OLDVALUES"].ToString(); and slip in array and then you can set global variables and access them in your code. Remember its a SandBox solution approach for event receivers, not for farm solution.

Bharat Sukhwal

May 5th, 2014 9:43am

A property bag should be used to fix this issue. I've done it successfully in the past. There is a good example at this link... http://sharepoint.stackexchange.com/questions/26855/sharepoint-property-bags 
Free Windows Admin Tool Kit Click here and download it now
May 5th, 2014 1:42pm

enable history on the list set retain maximum version around 2 in ItemUpdated(only o item updated, since item added tou have just one version) you can use item.versions[0] current item values item.versions[1] before item values i think this is the best approach if you need some value of item. better than use cache, since cache is per server, not per user, so the key would ve itemid and user Id.
March 28th, 2015 4:20pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics