locked
Update a field on parent list based on updated fields from grandchild list using workflow(s) RRS feed

  • Question

  • Hi guys, I have a complex situation that I was wondering if you guys have an idea on how to do:

     

    So, I have 3 lists, the parent, child, and grandchild list. The parent list can have one or many child, and a child can have one or many grandchild. There is a option field on parent called status, which I want to set to "complete" when the option fields that is associated with the grandchild that the parent is associated to is all set to "complete". So let's say, parent A has child 1, who has grandchild i and ii. Grandchild i and grandchild ii has their status updated to "complete", and when that happens, parent A's status is set to "complete". Is workflow the best solution to this problem?

     

    Hopefully this explaination of my problem is clear enough. Please let me know if you need any clarification, all help are appreciated, thanks!

    Friday, July 29, 2011 2:28 PM

Answers

All replies

  • I think instead of workflow you need to attach custom event handler in the grandchild list (ItemUpdated).

    code should be like below

    ----

    -----

    SPListItem objItem = properties.ListItem;

    If(Convert.ToString(objItem["Status"] == "Complete")

    {

      SPListItem objChildItems =objItem.ParentWeb.Lists["ChildList"].getitembyid (convert.toInt32( objItem["ChildID"]));

     SPListItem objParentItems =objItem.ParentWeb.Lists["Parent"].getitembyid (convert.toInt32( objChildItems ["ParentID"]));

    objParentItems["status"] = "Complete";

    objParentItems.Systemupdate(false);

    }


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!
    Friday, July 29, 2011 2:39 PM
  • Hi Rahul, thanks for answering my question again and so prompty.

    But a few questions though because I'm a total nooby at writing codes.

    Where would I have to put this code within the page, and on which aspx page of the grandchild list (I navigated to the List grandchild in SPD, and there are like a bunch of aspx pages because of all the different views, or is it not on an aspx page?)

    Is this the only code that I need? or is it only a portion of the code and I need to add on to it?

    How do I figure out the ID of the child and parent list (the (objectItem["childID"] and objectChildItems["ParentID"] part)

    What about the name of the list ( the .Lists["ChildList"] and .Lists["Parent"] part) 

    Does it only update after all the child's status that is associated with the parent is set to complete?

     

    Thank you so much!!!


    Friday, July 29, 2011 3:06 PM
  • see you dont need to write the code in aspx pages . you need to add eventreceiver to the grandchild list to update list item . you can get the litsitem id from the listitem. 

    for event receiver you can refer below links

    http://msdn.microsoft.com/en-us/library/ms453149.aspx

    http://msdn.microsoft.com/en-us/library/bb736146(v=office.12).aspx

    http://www.fsmpi.uni-bayreuth.de/~dun3/archives/getting-started-with-custom-sharepoint-event-receivers/161.html.

    You can create the lookup column of parent list and in grandchild list .

    it will update only on item bases. but offcourse you need to write your custom logic to get all fields check the status and update accordingly


    Rahul Sharma -------------------------- Coding is all about passion !!!!!!
    Friday, July 29, 2011 3:18 PM
  • Thank you so much Rahul!

    I think I can take it from here.

    -Peter

    Friday, July 29, 2011 3:23 PM