0

The reason I offer both of those languages is that I can achieve what I'm trying to accomplish using either javascript, or C#, but they are completely different languages. I couldn't find any sort of this functionality in the workflows in sharepoint designer.

3 Answers 3

6

The easiest way to invoke some code on submission (...insert) of a list item it to write an ItemAdded event receiver. The item level event receiver can be registered against a web, list or content type. Here's an example of registering one against a web (...this would fire for an item added to any list or library on the web:

SPEventReceiverDefinition itemAdded = web.EventReceivers.Add();
itemAdded.Type = SPEventReceiverType.ItemAdded;
itemAdded.Assembly = "MyAssemly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=141fe4b547d7494f";
itemAdded.Class = "MyClass";
itemAdded.SequenceNumber = 100;
itemAdded.Update();

And then the event receiver would look something like this:

public class EventReceivers : SPItemEventReceiver
{
    public override void ItemAdded(SPItemEventProperties properties)
    {
       // perform ItemAdded operation
    }
}
2
  • If I can just check one thing with you: Using SequenceNumbers below 10000 is not recommended because Microsoft 'reserved' them for OOTB receivers. I have heard or read about it in the past but right now I cannot find any valid information on the web (except some random forums). Commented Jul 30, 2011 at 22:26
  • I've heard that before, but I'm not aware of any guidance direct from Microsoft on that. There could also conceivably be scenarios where you are doing something where it's absolutely necessary that your event receiver runs first.
    – Rob D'Oria
    Commented Jul 31, 2011 at 0:00
1

You could use an Event Receiver. From the article:

What is a custom event handler? A custom event handler is a .Net assembly that contains the additional business logic you need to run when the event occurs in SharePoint.

You'll probably need to implement the ItemAdding and/or ItemAdded event(s).

1

Javascript code can be run but utilizing the PreSaveAction() function. This will allow you to execute any javascript code you need to on the list item submission before the item is commited to the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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