none
[URGENT] Jquery related issues RRS feed

  • Question

  • I have 2 lists and i have below code which is not working based on the below scenario

    List Details

    List Name : Test 

    Country (single line of text)

    Location (single line of text)

    Mobile (single line of text)

    Manager (person or group)

    List Name: TestDetails

    Name (lookup) get information from Test

    Country (single line of text)

    Location (single line of text)

    Mobile (single line of text)

    Manager (single line of Text)

    ------------------------------------------

    scenario: when i click OOTB new item form in Testdetails list and Click name lookup then it should populate the values automatically from the another list Test for the columns Country,Location,Mobile,Manager in the Testdetails newform

    Blitz



    • Edited by sree_23 Tuesday, July 9, 2019 5:40 AM
    Friday, July 5, 2019 10:33 AM

Answers

  • Hi,

    JavaScript Case Sensitive, make sure the case is right.

    Test script and result.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                var ID;
                $('select[title= "Name"]').change(function () {
                    ID = $('select[title= "Name"] option:selected').val();
                    $().SPServices({
                        operation: "GetListItems",
                        async: false,
                        listName: "Test",
                        CAMLViewFields: "<ViewFields><FieldRef Name='Country'/>, <FieldRef Name='Location'/>,<FieldRef Name='Mobile'/>,<FieldRef Name='Manager'/> </ViewFields>",
                        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>",
                        completefunc: function (xData, Status) {
                            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                                var Country = $(this).attr("ows_Country");
                                $('input[title="Country"]').val(Country);
                                $("input[Title='Country']").attr("disabled", "disabled");                          
                                var Location = $(this).attr("ows_Location");
                                $('input[title="Location"]').val(Location);
                                $("input[Title='Location']").attr("disabled", "disabled");                            
                                var Mobile = $(this).attr("ows_Mobile");
                                $('input[title="Mobile"]').val(Mobile);
                                $("input[Title='Mobile']").attr("disabled", "disabled");                            
                                var Manager = $(this).attr("ows_Manager");
                                Manager = Manager.replace(/[^a-z ;]/gi, '');
                                var re = /;;/gi;
                                var re1 = / /gi;                            
                                Manager1 = Manager.replace(re, ';');
                                Manager1 = Manager1.replace(re1, ', ');
                                Manager1 = Manager1.substring(1);                            
                                $('input[title="Manager"]').val(Manager1);
                                $("input[Title='Manager']").attr("disabled", "disabled");                            
                            });
                        }
                    });
                });
    
            });
    
            function PreSaveAction() {
    
                $("input[Title='Country']").attr("disabled", "");
                $("input[Title='Location']").attr("disabled", "");
                $("input[Title='MOBILE']").attr("disabled", "");
                $("input[Title='Manager']").attr("disabled", "");
    
                return true;
    
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Proposed as answer by Dennis GuoModerator Tuesday, July 9, 2019 8:09 AM
    • Marked as answer by sree_23 Tuesday, July 9, 2019 2:34 PM
    Monday, July 8, 2019 6:13 AM
  • Hi,

    For required filed type, try below code.

    [Title*='Country'] means Title contains Country.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                var ID;
                $('select[title= "Name"]').change(function () {
                    ID = $('select[title= "Name"] option:selected').val();
                    $().SPServices({
                        operation: "GetListItems",
                        async: false,
                        listName: "Test",
                        CAMLViewFields: "<ViewFields><FieldRef Name='Country'/>, <FieldRef Name='Location'/>,<FieldRef Name='Mobile'/>,<FieldRef Name='Manager'/> </ViewFields>",
                        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>",
                        completefunc: function (xData, Status) {
                            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                                var Country = $(this).attr("ows_Country");
                                $('input[title*="Country"]').val(Country);
                                $("input[Title*='Country']").attr("disabled", "disabled");                          
                                var Location = $(this).attr("ows_Location");
                                $('input[title*="Location"]').val(Location);
                                $("input[Title*='Location']").attr("disabled", "disabled");                            
                                var Mobile = $(this).attr("ows_Mobile");
                                $('input[title*="Mobile"]').val(Mobile);
                                $("input[Title*='Mobile']").attr("disabled", "disabled");                            
                                var Manager = $(this).attr("ows_Manager");
                                Manager = Manager.replace(/[^a-z ;]/gi, '');
                                var re = /;;/gi;
                                var re1 = / /gi;                            
                                Manager1 = Manager.replace(re, ';');
                                Manager1 = Manager1.replace(re1, ', ');
                                Manager1 = Manager1.substring(1);                            
                                $('input[title*="Manager"]').val(Manager1);
                                $("input[Title*='Manager']").attr("disabled", "disabled");                            
                            });
                        }
                    });
                });
    
            });
    
            function PreSaveAction() {
    
                $("input[Title*='Country']").attr("disabled", "");
                $("input[Title*='Location']").attr("disabled", "");
                $("input[Title*='MOBILE']").attr("disabled", "");
                $("input[Title*='Manager']").attr("disabled", "");
    
                return true;
    
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Wednesday, July 10, 2019 6:26 AM
    Wednesday, July 10, 2019 1:27 AM

All replies

  • Hi,

    JavaScript Case Sensitive, make sure the case is right.

    Test script and result.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                var ID;
                $('select[title= "Name"]').change(function () {
                    ID = $('select[title= "Name"] option:selected').val();
                    $().SPServices({
                        operation: "GetListItems",
                        async: false,
                        listName: "Test",
                        CAMLViewFields: "<ViewFields><FieldRef Name='Country'/>, <FieldRef Name='Location'/>,<FieldRef Name='Mobile'/>,<FieldRef Name='Manager'/> </ViewFields>",
                        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>",
                        completefunc: function (xData, Status) {
                            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                                var Country = $(this).attr("ows_Country");
                                $('input[title="Country"]').val(Country);
                                $("input[Title='Country']").attr("disabled", "disabled");                          
                                var Location = $(this).attr("ows_Location");
                                $('input[title="Location"]').val(Location);
                                $("input[Title='Location']").attr("disabled", "disabled");                            
                                var Mobile = $(this).attr("ows_Mobile");
                                $('input[title="Mobile"]').val(Mobile);
                                $("input[Title='Mobile']").attr("disabled", "disabled");                            
                                var Manager = $(this).attr("ows_Manager");
                                Manager = Manager.replace(/[^a-z ;]/gi, '');
                                var re = /;;/gi;
                                var re1 = / /gi;                            
                                Manager1 = Manager.replace(re, ';');
                                Manager1 = Manager1.replace(re1, ', ');
                                Manager1 = Manager1.substring(1);                            
                                $('input[title="Manager"]').val(Manager1);
                                $("input[Title='Manager']").attr("disabled", "disabled");                            
                            });
                        }
                    });
                });
    
            });
    
            function PreSaveAction() {
    
                $("input[Title='Country']").attr("disabled", "");
                $("input[Title='Location']").attr("disabled", "");
                $("input[Title='MOBILE']").attr("disabled", "");
                $("input[Title='Manager']").attr("disabled", "");
    
                return true;
    
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Proposed as answer by Dennis GuoModerator Tuesday, July 9, 2019 8:09 AM
    • Marked as answer by sree_23 Tuesday, July 9, 2019 2:34 PM
    Monday, July 8, 2019 6:13 AM
  • Thanks.

    I am getting below error in  browser console, really not sure if some reference files conflicted also i tried using alerts but unfortunately alerts also not getting triggered

    error: object does not support property or method spservices


    Blitz

    Tuesday, July 9, 2019 8:30 AM
  • Hi,

    The error shows the SPServices not loaded correctly, just get it from the url I shared and save to your site assets library and reference one time(your sample code reference the library two times, may conflict).

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 9, 2019 8:39 AM
  • Hi,

    I have saved to the site assets library and same referenced in code but no luck.also alert is not getting triggered for further troubleshooting.Kindly help


    Blitz

    Tuesday, July 9, 2019 8:48 AM
  • Hi,

    Use developer tool to check the library loaded correctly(you should see the library content) and no duplicate reference.


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 9, 2019 8:54 AM
  • Hi,

    I verified Libraries loaded correctly and there is no duplicate references for the same.

    Kindly help


    Blitz

    Tuesday, July 9, 2019 9:18 AM
  • Hi,

    So it should be case-sensitive and the dropdown not find, check it.


    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 9, 2019 9:22 AM
  • Hi,

    I verified the same, it looks fine and lookup field seems to be correct and there is no issues. overall i am unable to see alerts getting triggered


    Blitz

    Tuesday, July 9, 2019 9:28 AM
  • I am not sure Onselection of lookupfield value,data is not getting loaded in the Newform for the respective fields

    Blitz

    Tuesday, July 9, 2019 9:52 AM
  • Additionally,below fields are required fields in  both the lists

    Country  -Required field

    Location -Required field

    Mobile-Required field

    Manager-Required field


    Blitz

    Tuesday, July 9, 2019 10:49 AM
  • I tested and it seems code is working if the fields are not required fields but its getting failed if fields are required.Kindly help

    Blitz

    Tuesday, July 9, 2019 11:00 AM
  • Kindly help to set the value of the field if its required field in the above code

    Blitz

    Tuesday, July 9, 2019 11:25 AM
  • Hi,

    For required filed type, try below code.

    [Title*='Country'] means Title contains Country.

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices-2014.02.min.js"></script>
        <script language="javascript" type="text/javascript">
            $(document).ready(function () {
                var ID;
                $('select[title= "Name"]').change(function () {
                    ID = $('select[title= "Name"] option:selected').val();
                    $().SPServices({
                        operation: "GetListItems",
                        async: false,
                        listName: "Test",
                        CAMLViewFields: "<ViewFields><FieldRef Name='Country'/>, <FieldRef Name='Location'/>,<FieldRef Name='Mobile'/>,<FieldRef Name='Manager'/> </ViewFields>",
                        CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'>" + ID + "</Value></Eq></Where></Query>",
                        completefunc: function (xData, Status) {
                            $(xData.responseXML).SPFilterNode("z:row").each(function () {
                                var Country = $(this).attr("ows_Country");
                                $('input[title*="Country"]').val(Country);
                                $("input[Title*='Country']").attr("disabled", "disabled");                          
                                var Location = $(this).attr("ows_Location");
                                $('input[title*="Location"]').val(Location);
                                $("input[Title*='Location']").attr("disabled", "disabled");                            
                                var Mobile = $(this).attr("ows_Mobile");
                                $('input[title*="Mobile"]').val(Mobile);
                                $("input[Title*='Mobile']").attr("disabled", "disabled");                            
                                var Manager = $(this).attr("ows_Manager");
                                Manager = Manager.replace(/[^a-z ;]/gi, '');
                                var re = /;;/gi;
                                var re1 = / /gi;                            
                                Manager1 = Manager.replace(re, ';');
                                Manager1 = Manager1.replace(re1, ', ');
                                Manager1 = Manager1.substring(1);                            
                                $('input[title*="Manager"]').val(Manager1);
                                $("input[Title*='Manager']").attr("disabled", "disabled");                            
                            });
                        }
                    });
                });
    
            });
    
            function PreSaveAction() {
    
                $("input[Title*='Country']").attr("disabled", "");
                $("input[Title*='Location']").attr("disabled", "");
                $("input[Title*='MOBILE']").attr("disabled", "");
                $("input[Title*='Manager']").attr("disabled", "");
    
                return true;
    
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    • Marked as answer by sree_23 Wednesday, July 10, 2019 6:26 AM
    Wednesday, July 10, 2019 1:27 AM