Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

At Event Receiver Item Adding I must add name of worker which is adding a items to the list.

Here is my code:

SPListItem item = lstOtherList.Items.Add();
item["Kontrakt"] = properties.AfterProperties["Kontrakt1"];
item["Pracownik"] = properties.AfterProperties["Author"];
item["Dzien"] = dzienStart;
item["Procenty"] = properties.AfterProperties["Procenty"];
// item["ID z Czas Pracy Wpisy"] = properties.BeforeProperties["ID"];
dzienStart = dzienStart.AddDays(1.0);
item.Update();

I try Title Author but at Event Receiver it doesn't work and puts spaces. How can I get the user?

Update:

I was able to do it using the following code in Item Adding:

item["Pracownik"] = properties.UserDisplayName; 
share|improve this question

1 Answer 1

up vote 2 down vote accepted

Grzegorz,

On Item Adding the Author field is still not committed because the Item is not made yet..

A similar question is available here:
How to get current logged user in event receivers?

Or in your case if you decide not to make the event receiver synchronous, you can simply use the Author field in ItemAdded event and update the list item again!

I hope this helps

share|improve this answer
    
But how update in items added elements ? I must loop thro them each one ? –  Grzegorz Z Nov 21 '12 at 12:26
1  
No properties.ListItem will give you the ListItem just added... and you can access Author property here! –  Arsalan Adam Khatri Nov 21 '12 at 12:28
    
But how to get each items and then add only in items added kilkuosobowa field to each of elements on list which are added in items adding? –  Grzegorz Z Nov 21 '12 at 20:33
1  
ItemAdding event runs for single Item just before it is added to the List... and It should fire for each Item added to the list.. –  Arsalan Adam Khatri Nov 21 '12 at 21:18
    
As I tried it adding me first all elements for example 15 times, and next it"s adds me lookup field in Items Added and add me again 15 new elemens with only one column displays - lookup field. Next column isn't filed. And I want to only in Items Added add to in exist element a lookup field. –  Grzegorz Z Nov 22 '12 at 6:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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