Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.6k views
in SharePoint Server by 1 1 2

I need to look up a column based on another column in SharePoint form, I have checked this article SharePoint Auto Populate Column based on another Column. When I submit the script nothing seems to happen on my site. I tried both options text field and dropdown solutions. 

by 54 119 241
0 0
Hello TonyW, Have you tried to change the field name in the provided script based on your own field name! also Please, share with us the script that you have added on your side with your own field name so we can trace it.
by 54 119 241
0 0
Besides the above article, it's also recommended to check this article Auto Populate Field Values based on Lookup Selection In SharePoint https://spgeeks.devoworx.com/autofill-list-form-fields-based-on-lookup-selection-in-sharepoint/
by 1
0 0
Hello Mohamed El-Qassas

good the see the solution, i have create a list for test it, but nothing happen. could you help check what is wrong ?

<script language="javascript" src="https://2016sps.com/sites/SharePoint/SiteAssets/jquery%20files/jquery-1.10.2.min.js"></script>
<script language="javascript">
$(document).ready(function () {
// Set the lookup field name in the new form
var LookupField= $("input[title='Employee']");
LookupField.change(function () { PopulateLookupField(); });
});

var ListItem;
function PopulateLookupField() {
// Set the lookup field name in the new form   
var LookupField = $("input[title='Employee']").val();
if(LookupField)
{
var clientContext = new SP.ClientContext.get_current();
//set lookup list name
var LookupList = clientContext.get_web().get_lists().getByTitle('Employeelist');
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View><Query><Where><Eq> <FieldRef Name=\'Employee\' /> <Value Type=\'Text\'>' + LookupField + '</Value></Eq></Where></Query><RowLimit>1</RowLimit></View>');
ListItem = LookupList.getItems(camlQuery);
clientContext.load(ListItem);
clientContext.executeQueryAsync(Function.createDelegate(this,this.Succed),Function.createDelegate(this,this.Failed));
}
}
function Succed(sender, args) {

    if(ListItem.get_count()>0)
    {
        var item = ListItem.getItemAtIndex(0);
        // Text
        $("input[title='Name']").val(item.get_item('Name'));
        }
     else
     {
        // text
        $("input[title='Name']").val('');
         alert("There is no match !");
     }
}

function Failed(sender, args) {
alert('Error. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>

it will report error: one or more field types are not installed properly ......

If you don’t ask, the answer is always NO!
...