I'm attempting to create a projects/tasks lists. When a user creates "ProjectA", I want to create a list of tasks based on the template that was selected for that project. In general, everything is working except:
when creating the project items, I want to set the Project field to the name of the project (ProjectA). The project field is a lookup to Projects (the initial list where they're creating the items). As such, I can't just pass "ProjectA" (I can't, right?), but attempting to locate that project from the itemlist collection is impossible as the item hasn't been added yet.
How do you assign the lookup field of another list based on an item you're adding in the current list?
Edit: Currently the event receiver on Projects -> ItemAdded (switched to ItemAdded) does this:
1) gets Projects, Tasks, and ProjectTemplates lists
2) creates a list of the ProjectTemplates where the template in Projects for the created item equals the template name.
3) adds Tasks based on the list from 2.
4) From the tasks generated in 3, it gets the lowest DateTime from the start dates added, gets the highest DateTime from the end dates added, and gets a count of the items. It then updates the ListItem for the projects.
This is working, except that in order to see the updates in item 4, you have to manually refresh. Otherwise it just shows the default fields (project name, project template).
(Final?) Edit: Figured out the issue with the list item rendering old data. The way to fix this is actually pretty simple: in the Elements.xml file for this particular event, update it to include:
<Receiver> //Other fields like Name, Type, etc. <Synchronization>Synchronous</Synchronization> </Receiver>
inside of the Receiver