0

I have 2 lookup fields on a form. I have the following code and it's populating the 2 lookup fields. However, when I click on save button it complaints about field is required but I see both are populated with the correct value. Any idea?

NWF$(document).ready(function () {
    var obj = NWF$('#' + vartestlookupID);
    //alert("Selected Name");
    obj.change(function () {

    var clientContext = SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var oList = clientContext.get_web().get_lists().getByTitle("EmployeeData");
    var listItem = oList.getItemById(this.value);
    clientContext.load(listItem);
    clientContext.executeQueryAsync(function () {
    document.getElementById(varFirstNameID).value = listItem.get_item('FirstName');
    document.getElementById(varLastNameID).value = listItem.get_item('LastName');
    document.getElementById(DepartmentName).value=listItem.get_item('DepartmentName').get_lookupId();
    document.getElementById(WorkLocation).value=listItem.get_item('WorkLocation').get_lookupId();   
    document.getElementById(Supervisor).value = listItem.get_item('Supervisor');        
    }, function () {        });
    });
});
0

I added 2 lines code right after setting each lookup field on the form.

NWF$("input[id='" + DepartmentName + "']").val(NWF$("#" + DepartmentName + " option:selected").val());

and

NWF$("input[id='" + WorkLocation + "']").val(NWF$("#" + WorkLocation + " option:selected").val());

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.