0

I am currently trying to develop an event receiver that uses properties.AfterProperties object in updating and ItemUpdated and ItemUpdating event, so can I get the BeforeProperties and AfterProperties in my ItemCheckedIn event or ItemCheckedout event? If I explain my scenario,when the user upload a document he will select a drop down,public and confidential,and when confidential is selected am triggering a custom action such that,3 people pickers were populated for entering the user names for giving access programmatically. I can say its a kind of approval workflow i am trying to implement through visual web part and event receiver -without using SP D 2013 / WF Manager. The strange thing is that, it works in my test and staging environment, but fails in production.

 public override void ItemUpdating(SPItemEventProperties properties)
    {
        base.ItemUpdating(properties);

        try
        {
            if (properties.AfterProperties["vti_sourcecontrolcheckedoutby"] == null
            && properties.BeforeProperties["vti_sourcecontrolcheckedoutby"] != null)
            {
                if (IsConfidential(properties))
                {
                    SetRoleChanged(properties);
                }
            }
    }
  public void SetRoleChanged(SPItemEventProperties properties)
    {
        try
        {
            string currentRead = 
        Convert.ToString(properties.AfterProperties[READACCESSCOL]);
            string oldRead = 
        Convert.ToString(properties.BeforeProperties[READACCESSCOL]);
            string x2 = 
        Convert.ToString(properties.ListItem[READACCESSCOL]);
        } 
       string currentView = 
        Convert.ToString(properties.AfterProperties[VIEWACCESSCOL]);
         string oldView = 
         Convert.ToString(properties.BeforeProperties[VIEWACCESSCOL]);
            if (currentView != oldView)
            {

                properties.AfterProperties["ViewChanged"] = "true";   
            }

      public override void ItemUpdated(SPItemEventProperties properties)
       {
        base.ItemUpdated(properties);
       }
4
  • Why are you not using ItemUpdated instead of ItemUpdating? May 31 '15 at 11:56
  • Did not use ItemUpdated.Will I get the values if I use ItemUpdated event? May 31 '15 at 12:00
  • Yes. Please use ItemUpdated May 31 '15 at 12:01
  • The weird thing is that, it works in my test and staging.But it fails in Production.So if the issue is in ItemUpdating, then my doubt is that, the issue should appear in the test and staging environments. We have tested thoroughly this in the above 2 environments and ported the content db back up to production and deployed the webpart's latest wsp. So as per my understanding there should not be an issue when triggering the event receiver.The only difference between in staging and production is, staging is <mydms.company.com> and production is in <mydms.company.com> . May 31 '15 at 12:09
0

Below is the list of supported Events for SPListItem

  • ItemAdding
  • ItemAdded
  • ItemDeleting
  • ItemDeleted
  • ItemUpdating
  • ItemUpdated
  • ItemFileConverted
  • ItemFileMoving
  • ItemFileMoved
  • ItemCheckingIn
  • ItemCheckedIn
  • ItemCheckingOut
  • ItemCheckedOut
  • ItemAttachmentAdding
  • ItemAttachmentAdded
  • ItemAttachmentDeleting
  • ItemAttachmentDeleted

You can use SPItemEventProperties properties to get hold of BeforeProperties and AfterProperties

5
  • Thank you for the reply. I am trying to get the value for two operations.One is when the user uploads the new document into the document library.My event receiver triggers correctly and I am able to get the values of 3 people picker values. in my scenario read_access,view_access, ContributeNoDel_Access people picker values.Now i am triggering one method and doing some manipulations.After this,when the same user or other user is trying to edit the same document he checked out and edit properties , i mean he edits the these 3 people picker values and save and checkedin. May 31 '15 at 11:35
  • You should handle event ItemCheckedIn and read those inside that method. May 31 '15 at 11:36
  • When the user CheckedIn after editing the properties,I mean, Editing the docmuent who has the necessary privileges, ItemUpdated event triggers and am saving 3 values and I need these values available in ItemcheckedIn method.Is this possible? May 31 '15 at 11:38
  • I have tried to access those values but those were, I am unable to get those saved values in ItemUpdated method in ItemCheckedIn method. May 31 '15 at 11:41
  • Update question and post relevant code. May 31 '15 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.