Update list data using data from another list

Sep 1, 2011 at 12:11 AM

So I have a Master list that contains a bunch of columns including one called "Application Code". I have another list, my "mapping" list that has 2 columns, one for Application Code, and another for Application Name. Application Code-->Application Name is a Many-->One relationship. My goal is populate a column in the Master list with the Application Name (which would be gathered from the "mapping" list). Sounded like an easy job for a lookup column, until I got into doing bulk loads of data into the Master List and the "Application Code" wasn't in the "mapping" list yet, thus I began dreaming up ideas on how to tackle this (and please feel free to give me a better one if you have one!!!). The idea I've come up with is to use the SPServices library and the SPUpdateMultipleListItems function to populate this "Application Name" column in the Master List. I really have no clue where to begin with this though and am really hoping theirs already an example out there (no luck finding one yet though after 3 days of research).

 

In a nutshell I want to go through the whole Master list row by row, grab the "Application Code", reference that against the "Application Code" in the "Mapping" list, return the "Application Name", and populate a column in the Master List with the "Application Name".

 

Any help is greatly appreciated.

Sep 5, 2011 at 6:09 PM

Got it!!! Hopefully this will be useful for someone else too:

 

<script src="/Config%20Files/jquery.min.js" type="text/javascript"></script>
<script src="/Config%20Files/jquery.SPServices-0.6.2.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">




function Update_App_Map_A()
{
    $('#pleasewait').show();
    $('#button').hide();
    $('#spacer').hide();
    setTimeout(Update_App_Map_B, 0);

    function Update_App_Map_B()
    {
        $().SPServices(
        {
            operation: "GetListItems",
            async: false,
            listName: "Active Server Intake",
            CAMLQuery: "<Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query>",   
            CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='AppCode' /></ViewFields>",
            CAMLRowLimit: 0,
            completefunc: function (xData, Status)
            {
              $(xData.responseXML).find("[nodeName='z:row']").each(function()
              {
                    ServerName=$(this).attr("ows_Title");
                    AppCode=($(this).attr("ows_AppCode")).split("#");

                    $().SPServices(
                    {
                        operation: "GetListItems",
                        async: false,
                        listName: "Intake Application Mapping",
                        CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+AppCode[1]+"</Value></Eq></Where></Query>",
                        CAMLViewFields: "<ViewFields><FieldRef Name='Intake_x0020_Application_x0020_N' /></ViewFields>",
                        CAMLRowLimit: 0,
                        completefunc: function (xData, Status)
                        {
                            $(xData.responseXML).find("[nodeName='z:row']").each(function()
                            {
                                $().SPServices.SPUpdateMultipleListItems(
                                {

                                    listName: "Active Server Intake",
                                    CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>"+ServerName+"</Value></Eq></Where></Query>",
                                    valuepairs: [["Intake_x0020_App_x0020_Name", $(this).attr("ows_Intake_x0020_Application_x0020_N")]]
                                });
                            });
                        }
                    });

              });
            }
        });
    $('#button').show();
    $('#pleasewait').hide();
    }
}
</script>




<div class="ms-rteFontSize-7" id="pleasewait" style="text-align: center; display: none"><span>Please Wait...</span></div>
<div style="text-align: center"><input id="button" onclick="Update_App_Map_A()" type="button" value="Update Intake"/>&#160;</div>