1

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

  • You can try ItemAdded event receiver instead of ItemAdding ? – Arsalan Adam Khatri Mar 5 '14 at 6:55
  • I've adjusted this to be an ItemAdded, but the only issue is that the parent project has a count of the tasks list items that were added. Is there a way to force a visual update of that item to include the counts? – Robert Mar 5 '14 at 13:41
  • Please check my answer below! – Arsalan Adam Khatri Mar 5 '14 at 13:53
  • @Robert just a suggestion, create sub-webs for projects then a listitem, would be helpful in future :) – Muhammad Raja Mar 5 '14 at 14:18
1

You can try ItemAdded event receiver instead of ItemAdding..

UPDATE

You can add one more event receiver on Tasks List, and on ItemAdded, ItemDeleted events you can get the Project Item (from Task Lookup Field).. and Count total number of Tasks for that Project (from Tasks List) and update the count in Projects list.. Does that makes sense?

  • I understand. Will that force the ListItem rendered in the Projects list to have the updated values or will it still require a refresh? – Robert Mar 5 '14 at 14:18
  • If you update the Projects Item to have the latest count, the latest value is there.. If the user has screen opened, it will have old values until he refreshes his browser :) However each time user tries to access, he will get latest count.. – Arsalan Adam Khatri Mar 5 '14 at 14:22
  • you're right. It does that off the Projects ItemAdded event as well, I'm just wondering if there is a way to refresh the page when an item is added automatically for them. – Robert Mar 5 '14 at 14:25
  • Ah, I found out how to do it. But your ItemAdding -> ItemAdded fixed the primary issue, so marking as answer. – Robert Mar 5 '14 at 14:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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