locked
Populate a List Item based on another List Item RRS feed

  • Question

  • Hello All,

    We have an UI where user selects a department. It goes into a List item. We have separate SharePoint user groups for each department.

    I want to populate the users in the SharePoint group in one of the list Item. So now based on department selected I need to populate the List Item.

    Please help me in doing this. I am able to get all the users in a group using:

                DropDownList ddl = new DropDownList();
                ArrayList al = new ArrayList();
                SPWeb web = SPContext.Current.Web;
                SPGroupCollection grpCln = web.Groups;
                foreach (SPGroup grp in grpCln)
                {
                    if (grp.Name == "Viewers")
                    {
                        foreach (SPUser user in grp.Users)
                        {
                            al.Add(user.Name);
                        }
                    }
                }
                ddl.DataSource = al;
                ddl.DataBind();

    
    
    
    Tuesday, December 8, 2009 3:50 PM

Answers

  • Well, you definitely took one of the harder paths, not impossible, I just don't have the InfoPath skills to tell you how to do it in the form itself.  You could always consider writting what I call an in-context web application.  It is an asp.net web application that exists in the _layouts directory.  You would have full access to the object model and could make as many forms as you wanted.  Could be an easier path for you.

    Chris

    Chris Givens CEO, Architecting Connected Systems Blog Twitter
    • Marked as answer by Grace Kim Friday, December 11, 2009 2:23 PM
    Friday, December 11, 2009 6:27 AM

All replies

  • Hi, can you rephrase that a bit differently?  Not quite sure what you are trying to do...are you trying to set the permissions on the item based on what the user selects in the drop down?
    Chris Givens CEO, Architecting Connected Systems Blog Twitter
    Tuesday, December 8, 2009 9:44 PM
  • As i suggest, You can use ajax for this scenerio.
    You need to write javascript and create object of XMLHTTP for this.

    Thanks.


    Maanu
    Wednesday, December 9, 2009 12:38 PM
  • Hi,

    I think you need to create connectable web parts. In case of connected web part, if the parent web part value changes then the child web part is refreshed automatically. So Usergroup web part will be connected to department web part by department id. The following links may help you:

    http://www.codeproject.com/KB/sharepoint/ConnectingCustomWebParts.aspx
    http://msdn.microsoft.com/en-us/library/ms469765.aspx


    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    Wednesday, December 9, 2009 2:48 PM
  • Hi Chris,

    I have a workflow that would generate a task. I want provision to assign the task to a person in the team belonging to a particular department. So during the workflow I am assigning the task to the department's SharePoint group.

    Now If I can get the users in a dropdown list when I edit the task, I can assign the task to a particular user.

    Thanks
    Wednesday, December 9, 2009 3:19 PM
  • Think I'm getting the picture, so in the task edit form of the task that is generated from the workflow, you will have a drop down populated with the users of the group that was selected when the item was created?  Are you using InfoPath forms or ASPX forms?
    Chris Givens CEO, Architecting Connected Systems Blog Twitter
    Wednesday, December 9, 2009 3:28 PM
  • You can iterate all the items within a list by reference the following *SAMPLE* code:

    SPSite oSiteCollection = SPContext.Current.Site;
    SPList oList =
       oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];

    SPListItemCollection collListItems = oList.Items;

    foreach (SPListItem oListItem in collListItems)
    {
        //Iteration.
    }

    More details: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx

    You can also use SPList.GetItems (SPQuery) to get a collection of items from the list based on the specified query.


    Cogito ergo sum.
    Thursday, December 10, 2009 1:43 AM
  • Chris,
    I am trying to use an InfoPath, however when I try to edit or view item it says Error occured but doesn't say what was the error. That is secondary I will fix it hopefully.

    Thursday, December 10, 2009 3:11 PM
  • And you have registered the task form properly in the workflow.xml and it shows up in Central admin as "Ready"?

    Chris
    Chris Givens CEO, Architecting Connected Systems Blog Twitter
    Thursday, December 10, 2009 4:14 PM
  • The InfoPath form is not Workflow enabled, It is ready though. Chris, since I am using an InfoPath is it possible to acheive the list of users in infoPath depending on the department? Should I write a VSTA program?

    I really appreciate your support.

    Thursday, December 10, 2009 6:23 PM
  • Well, you definitely took one of the harder paths, not impossible, I just don't have the InfoPath skills to tell you how to do it in the form itself.  You could always consider writting what I call an in-context web application.  It is an asp.net web application that exists in the _layouts directory.  You would have full access to the object model and could make as many forms as you wanted.  Could be an easier path for you.

    Chris

    Chris Givens CEO, Architecting Connected Systems Blog Twitter
    • Marked as answer by Grace Kim Friday, December 11, 2009 2:23 PM
    Friday, December 11, 2009 6:27 AM