Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

List Item Updating Eventreceiver

$
0
0

Hi,


I have a Sharepoint Designer-Workflow attached to a list with item-level-permissions. It is required that the creater of an item should not be able to alter or delete the item. Because SP-Designer-Workflows run with the privileges of the user that starts the workflow, I have to give him edit rights. In order to prevent altering I wrote this event-receiver:

  public override void ItemUpdating(SPItemEventProperties properties)
 {
//workflow impersonates as "System Account" with the rights of creator and sets workflow-state asyncronously

            if (creator == properties.UserDisplayName)
            {

                properties.Status = SPEventReceiverStatus.CancelWithError;
                properties.ErrorMessage = "Item cannot be manipulated after submitting";

            }

}

This thing works, BUT only if I include some code I used to debug this receiver with. I used a sharepoint-list to print out the values of fields because I failed to attach to that process. It iterates through the List the workflow is bound with and writes the fieldTitle and its changed value (AfterProperties) to a test-list.

foreach (SPField field in properties.Web.Lists["Acquisition"].Fields)
                {
                    SPWeb web = properties.Web;
                    SPList eventTest = web.Lists["EventTest"];
                    SPListItem test = eventTest.Items.Add();
                    test["Title"] = field.Title;
                    test["debug"] = properties.AfterProperties[field.Title];
                    test.Update();
                    eventTest.Update();
                }

...when that receiver seemed to be working, I removed the debug code and it stopped working. I have created another more complicated solution, which behaves the same.

I just don't understand...

Thank you for reading this






Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>