none
How to update a list item in the itemupdated or itemupdating event fired using Sharepoint Object Model in 2007 RRS feed

  • Pregunta

  • This is my scenario:

    When someone updates an item and sets a choice field to some value, i should catch the update (updating or updated) event fired and if that value matches some value predefined for me, it should update a datetime field with DateTime.Today value.

    But i cannot achieve this. When i click on the OK button in editform.aspx it updates the value, but the event doesn't seems to be fired or it is fired but doesn't update the list.

    Does anyone knows where am i going wrong, if i'm missing some code or propertie?

    Thanks in advance

    My code is:

    public override void ItemUpdated(SPItemEventProperties properties)
            {
                try
                {
                    this.DisableEventFiring();
                    if (properties.ListItem["Estado Testeo"].ToString() == "Listo para Impresión")
                    {
                        //properties.ListItem["Fecha del Test"].Text = "";

                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            using (SPSite oSite = new SPSite(properties.ListItem.Web.Site.ID))
                            {
                                using (SPWeb oWeb = oSite.AllWebs[properties.ListItem.Web.ID])
                                {
                                    SPList oList = oWeb.GetListFromUrl(oWeb.Url + <urlList>);
                                    SPListItem oItm = oList.GetItemById(properties.ListItemId);
                                    oItm["Fecha de Test"] = DateTime.Today;
                                    oItm.Update();
                                }
                            }
                        });
                    }
                    else properties.ListItem["Fecha de Test"] = "";
                }
                catch (Exception ex)
                {
                    properties.ErrorMessage = "Error al intentar modificar la tarea del auditor.\r\n" + ex.Message;
                    properties.Cancel = true;
                }
                finally
                {
                    this.EnableEventFiring();
                }
            }


    Regards, Joel Di Rosa

    lunes, 18 de junio de 2012 19:22

Todas las respuestas

  • Hi,

    Have you tried to debug your event receiver?

    Regards


    ------------------------------------------------------------
    Juan Carlos González Martín MVP de SharePoint Server
    Director revista CompartiMOSS: http://www.gavd.net/servers/compartimoss/compartimoss_main.aspx
    Blog: http://geeks.ms/blogs/ciin
    Twitter: @jcgm1978
    ------------------------------------------------------------

    lunes, 18 de junio de 2012 21:01
  • No, i haven't. I'm developing in another machine instead of the sharepoint server. Is there any other way i could debug the event receiver?

    Regards, Joel Di Rosa

    martes, 19 de junio de 2012 14:44