0

I have two SharePoint lists. List #1 contains "static" information such as project number, geographic location, region, and planned inspection type. List #2 is a list that I want to use as a way to track inspection findings. List#2 will have a lookup column that will be used to pick the project number. Once this project number is picked other fields will be populated based upon that project number. Any thoughts how I can achieve this? Thank you in advance.

  • Do the "other fields" need to be populated in real-time (as soon as the Project Number is chosen or changed), or can you have the "other fields" be populated when the item is saved? – C. Dennett Aug 17 '18 at 18:31
  • 1
    I think that you need to extend the requirement to handle changes to the project list as well, unless the information in that list can't be changed or that the changes shouldn't be copied to the second list? – Kasper Bo Larsen Aug 17 '18 at 18:53
  • If you're open to using a coding solution, you can do this using REST API calls. I guess it depends on what version of SP you're on as well as to whether REST is an option or not. – Nate Aug 20 '18 at 19:06
  • Thank you for your input! List #1 - static list - is essentially a list I would maintain. List #2 - essentially a user form - would be used by our Construction Engineers (CE) to track findings on a particular project. I didn't make that very clear. So when the CEs go into SharePoint, they would pull up List #2 or the user form, plug in the project number and certain other fields would populate as well. This autopopulation would have to occur in real time and not when the form (list) is saved. Our agency uses SharePoint 2010. – simmongr Aug 22 '18 at 16:39
0

I would use WF for that. WF triggers when item is updated if the field ProjectNo was populated it will copy the values from the other list.

  • Thank you Marek! Can you elaborate on WF? My apologies in advance, I am new to SharePoint. – simmongr Aug 22 '18 at 16:42
  • I think LZ_MSFT option will be better for you. In WF those values would be populated after the item is created during creation of item so from user perspective a bit more friendly. IF you want to investigate WF google for some SHarepoint Designer WF tutorials. WF is technology in its own right, you can always get back if you have some specific questions. – Marek Sarad Aug 23 '18 at 13:10
0

The following example for your reference.

1.Create a custom list "List1" and add two text columns "ProjectNumber" and "GeographicLocation" to this list.

2.Create a custom list "List2" and add a lookup column "ProjectNumber"(lookup from List1 ProjectNumber column) and text column "GeographicLocation".

3.Add following code into new form page in the "List2".

<script src="https://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    $("select[title='ProjectNumber']").change(function(){
        var pnumber=$(this).val();
        var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('List1')/items("+pnumber+")";
        $.ajax({
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {       
                var item = data.d;
                $("input[title='GeographicLocation']").val(item.GeographicLocation);        
            },
            error: function (error) {
                console.log(JSON.stringify(error));
            }
        });
    });
});
</script>

4.When you change a value of the "ProjectNumber" field in newform.aspx in "List2", the "GeographicLocation" will auto populated.

enter image description here

If you use SharePoint 2010, modify the "webUrl" and "listName" in the code below, and add the code below into content editor web part in the newform.aspx page in List2.

<script src="https://code.jquery.com/jquery-1.11.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    $("select[title='ProjectNumber']").change(function(){
        var pnumber=$(this).val();
        var webUrl="http://sp2010";
        var listName="List1";
        var url = webUrl + "/_vti_bin/listdata.svc/"+ listName + "(" + pnumber + ")";;
        $.ajax({
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {       
                var item = data.d;
                $("input[title='GeographicLocation']").val(item.GeographicLocation);        
            },
            error: function (error) {
                console.log(JSON.stringify(error));
            }
        });
    });
});
</script>
  • Where would I place this code in SharePoint? I am using SharePoint 2010. – simmongr Aug 22 '18 at 16:44
  • I modify the reply, check it. we can add code into content editor web part in SharePoint 2010. – LZ_MSFT Aug 23 '18 at 1:25

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.