Answered by:
[URGENT] Jquery related issues

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
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
-
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
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
-
-
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. -
-
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. -
-
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.- Edited by Lee__liMicrosoft contingent staff Tuesday, July 9, 2019 9:22 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