locked
How to achieve values in second list (2-list connection) RRS feed

  • Question

  • HI ,

    List1

    ColA ,ColB

    100,292929

    200,282726

    300,218794

    List2

    ColC, ColD

    (100,200,300)-As ColC is look up type so these entered values are coming as drop down when i choose one then respective value from list1 should come in List2 ColD

    E.g if 100 i select then 292929 should come.

    Please guide me how can i get this?

    Thanks in advance.


    sudhanshu sharma Do good and cast it into river :)
    • Edited by sudhanshuSharma Monday, January 30, 2012 5:29 AM
    • Moved by Mike Walsh FIN Monday, January 30, 2012 6:34 AM No reference to any BI function (From:SharePoint - Business Intelligence (pre-SharePoint 2010))
    Monday, January 30, 2012 5:11 AM

Answers

All replies

  • Hi Sudhanshu,

    There is no OOB solution for this MOSS 2007. You'll have to create a custom SharePoint field. Refer to the following link on how to create a custom field type:

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


    Thanks Arut
    Monday, January 30, 2012 9:35 AM
  • Where is the code?
    Thanks Arut
    Monday, January 30, 2012 12:34 PM
  • I have got my program output but when item added not while filling form means on item adding

    How can i get same thing on Itemadding

    i have changed From item added to item adding  but nothing works-

     


    sudhanshu sharma Do good and cast it into river :)
    Monday, January 30, 2012 1:00 PM
  • Hi,

    Could you explain you scenario? As well as post your source code? 


    Thanks Arut
    Monday, January 30, 2012 1:16 PM

  • HI ArutJothi,

    For Scenario Please visit this-
    http://social.technet.microsoft.com/Forums/en-US/sharepointcollaboration/thread/3e27f75b-c478-42f7-ba2e-60a92f3ff3db



    and in source code i have written a event receiver class

    which is  implementing this algorithm.

    using System;
    using System.Collections.Generic;
    using System.Collections;
    using System.Linq;
    using System.Text;
    using Microsoft.SharePoint;
    using System.Net.Mail;
    using System.Diagnostics;
    using System.Windows;

    namespace RPM_OnItemAddingEventReceiver
    {
        public class RPM_OnItemAdding : SPItemEventReceiver
        {
            public override void ItemAdded(SPItemEventProperties properties)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    EventLog.WriteEntry("ItemAdded", "ItemAdded");
                });
                System.Diagnostics.Debugger.Break();
                if (properties.ListTitle == "List2")
                {
                   try
                    {
                        using (SPSite spSite = new SPSite("http://172.20.14.16:44/Collaboration/Lists"))
                        {
                            using (SPWeb spWeb = spSite.OpenWeb())
                            {
                                SPList spList = spWeb.Lists["List2"];
                              

                                SPListItem item = properties.ListItem;
                  
                       

                       
            
                        if (item["RSOR Number"] != null)
                        {
                         
                          
                            SPFieldUserValue userValue = new SPFieldUserValue(spWeb, item["ColC"].ToString());
                            string userName = userValue.LookupValue;

                            Console.WriteLine("Value" + userName);//Testing done

                            if (userName != null)
                            {
                                using (SPSite spSite1 = new SPSite("http://172.20.14.16:44/Collaboration/Lists"))
                                {
                                    using (SPWeb spWeb1 = spSite1.OpenWeb())
                                    {
                                      
                                        SPList spList1 = spWeb1.Lists["List1"];

                                        SPListItem item1 = properties.ListItem;
                                      
                                        String strViewName = "AllItems.aspx";
                                    
                                    

                                        SPView view = properties.OpenWeb().GetViewFromUrl("http://172.20.14.16:44/Collaboration/Lists/SOR%20Response_SCG/" + strViewName);
                                        SPListItemCollection collListItems = spList1.GetItems(view);
                                        if (collListItems.Count > 1)//
                                        {
     
                                            string psno_scg = userName;
                                          
                                            SPQuery query = new SPQuery();
                                           
                                            query.Query = "<Where><Eq><FieldRef Name='Resource_x0020_PS_x0020_Number'/><Value Type='Text'>" + psno_scg + "</Value></Eq></Where>";
                                          
                                            SPListItemCollection items = spList1.GetItems(query);
                                            SPListItem nitem = items[0];
                                      
                                      
                                          
                                            string psno_rpm = nitem.DisplayName;

                                            item["PS_Number"] = psno_rpm;
                                            item.Update();
                                          
                                          
                                         }
                                      }
                                  }
                               
     
                           
                            }




                        }







                       
                    }



                

                 }
              }
                   
                   catch (Exception ex)
                    {
                        ex.ToString();
                    }


                }


            }
        }
      }
       




    sudhanshu sharma Do good and cast it into river :)
    Monday, January 30, 2012 1:25 PM
  • Hi,

    (a) How are you registering this event receiver?

    (b) Why are you creating SPSite and SPWeb objects from hard-coded URL? Your SPItemEventProperties fetch you the current web and site objects. Your SPItemEventProperties will also return the current list as SPList object.

    Your code seems to execute the required functionality, but is the ItemAdding event getting triggered?


    Thanks Arut
    • Edited by arutjothi Monday, January 30, 2012 1:47 PM
    Monday, January 30, 2012 1:44 PM
  • Hi Sudhanshu,

    How are you regestring your events, I guess through feature and did you modify your feature referencing ItemAdding as the type,

    <Type>
    ItemAdding
    </Type>

    Here is a link for Event Troubleshooting http://msdn.microsoft.com/en-us/library/aa979520(v=office.12).aspx

    Reference link for Event Handler : http://koenvosters.wordpress.com/2009/07/31/howto-create-an-event-handler-for-sharepointmoss-2007/

    HTH

    Thanks,
    Skancharla

     



    • Edited by Skancharla Monday, January 30, 2012 7:31 PM
    Monday, January 30, 2012 7:28 PM
  • I HAve changed type in xml then gac refresh ,feature deactivate and again activate but i am getting these values only on submission of form(on ok button click) i want values when i select value from drop down.

    while debugging i have seen for  item adding i am getting null here

     SPListItem item = properties.ListItem;//item is null

    but in item added item not null

    Please suggest what shud i do now?


    sudhanshu sharma Do good and cast it into river :)
    Tuesday, January 31, 2012 5:02 AM
  • In ItemAdding, the properties.ListItem will be null. This is a known bug in MS SharePoint Object model. Check the following link on the known behavior:

    http://sharing-the-experience.blogspot.in/2011/03/spitemeventproperties-itemupdated.html


    Thanks Arut
    Tuesday, January 31, 2012 5:29 AM
  • Hmm,

    So what should i do for this bug  can i not  proceed?

    Java script is only solution then?

     

    Moderator Note: How many more times do you need to be told the word is SHOULD not SHUD ?


    sudhanshu sharma Do good and cast it into river :)
    • Edited by Mike Walsh FIN Tuesday, January 31, 2012 8:26 AM Again corrected Shud with Should.
    Tuesday, January 31, 2012 5:33 AM
  • Why do you need to use ItemAdding here? I do not see any validation being done in your code that would require usage of ItemAdding only. If you are not doing any validation and prevent item from being added upon meeting a certain criteria, there is no need to use ItemAdding.

    Alternatively, you could use the following to get the required value:

    properties.AfterProperties["RSOR Number"]


    Thanks Arut
    Tuesday, January 31, 2012 5:51 AM
  • I am writing onitem adding bcause when i do new item and select value from first column drop down then only in second column values shud appear from 1st list
    and i changed

    if (item["RSOR Number"] != null) with below line

       if (properties.AfterProperties["RSOR Number"]!=null)

    but also i am going out of if as it is null but on form i select value from drop down

     


    sudhanshu sharma Do good and cast it into river :)
    Tuesday, January 31, 2012 6:16 AM
  • I'm still not convinced as to why you chose to go for ItemAdding. You need to understand that while new list item addition, both ItemAdding and ItemAdded will get executed. Only difference between them is that in any scenario if you want the item being added to the list, you go for ItemAdding method. I guess in your scenario, you can actually go for ItemAdded.

    Coming to why 'properties.AfterProperties["RSOR Number"]' is returning null, did you check if the field name is correct. Note that the field display name might be different from the actual field name or internal name and it is always advisable to use field internal name. Try using that following before your code:

    properties.List.Fields["RSOR Number"]

    or 

    properties.List.Fields[str].GetType().ToString()

    if the above doesn't fetch any value, the most probably you field name is incorrect.

     


    Thanks Arut
    Tuesday, January 31, 2012 6:48 AM
  • i elaborate my requirement -

    I have 2 list SCG and RPM

    SCG has fields

    SOR NUmber,PS Number

    1111,293131

    222,293132

    these entries i made in 1st list

     now in RPM list

    RSOR Number(look up type value receive from SOR Number SCG List),PS_Number

    in this list when i make entries i select values from drop down as 1111 and 2222 is coming in drop down when select 1111 then 293131 shud come(mapping from scg list) and on select 2222 ,293132 should come when it will come i will save entry .

    Now you suggest how can i achieve this i tried with item adding

    Thanks


    sudhanshu sharma Do good and cast it into river :)
    Tuesday, January 31, 2012 7:23 AM
  • Do you mean that while adding a new item, you may try changing the drop down field value multiple times before you click on Save button?And, before clicking save button, the other field should display the corresponding PS Number value.

    If yes, then I don't think event receiver is the right way to do this at all. Because, the item event receiver methods (both adding and added) will get executed when you click 'Save' in the new item form. However, ItemAdding method executes before the new item is actually committed to the SharePoint DB, while ItemAdded method executes after the new item was committed to the SharePoint DB. 

    Probably, you need to create a custom SharePoint field that will fetch the values from list 'SCM' and show the value in the format 'SORNumber-PSNumber'. This way user will be able to see both the values in the drop down.


    Thanks Arut
    Tuesday, January 31, 2012 9:23 AM
  • OK then can you give some relevant links how to create custom fields and how to proceed
    to achieve this

    sudhanshu sharma Do good and cast it into river :)
    Tuesday, January 31, 2012 12:20 PM
  • As mentioned in my first reply, the following link will give you an idea of how to create a custom SharePoint field:

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

    You will have to frame your own logic to handle the required scenario


    Thanks Arut
    Tuesday, January 31, 2012 12:47 PM
  • hi,

    May i get ur ID ?if dont mind


    sudhanshu sharma Do good and cast it into river :)

    Wednesday, May 23, 2012 12:19 PM
  • I was offline for a while and hence. couldn't respond. You can reach me at arutjothi.mv@hotmail.com or better to respond thru this thread (as I keep checking this forum)...

    Thanks Arut

    Monday, June 4, 2012 5:07 AM