AnsweredAssumed Answered

Setting fields using jQuery

Question asked by fmog on Mar 17, 2016
Latest reply on Apr 12, 2017 by dominic.white@lonza.com

I have following code and I am able to query a list and populate all the other field type (string, date/time, choice, lookup). However, I need to also copy Supervisor name from the query list and set it on the form. Am I missing anything or not taking the correct approach?

 

NWF$(document).ready(function () {
    var obj = NWF$('#' + vartestlookupID);
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, "FirstName", "LastName", "EmployeeName", "Title", "Department", "Location", "Classification", "Payroll");
clientContext.load(listItem);
    clientContext.executeQueryAsync(function () {
var varSupervisorID = listItem.get_item('SupervisorName').get_lookupValue();
alert((varSupervisorID));  // works and show Supervisor's Name
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();
var edDate = new Date(listItem.get_item('EffectiveDate1'));
var edDateFormat = (edDate.getMonth() + "/" + edDate.getDate() + "/" + edDate.getFullYear());
document.getElementById(varEffectiveDateID).value = edDateFormat;
  // DID NOT WORK document.getElementById(SupervisorName).value=listItem.get_item('SupervisorName').get_lookupId();
// DID NOT WORK document.getElementById(SupervisorName).value=listItem.get_item('SupervisorName').get_lookupValue();
var varSupervisorName = new NF.PeoplePickerApi('#SupervisorName');
  varSupervisorName.search(varSupervisorID).done(function (data) {varSupervisorName.add(data[0]);});
//varSupervisorName.search(listItem.get_item('SupervisorName').get_lookupId()).done function(data){varSupervisorName.add(data[0]);
//document.getElementById(SupervisorName).value = varSupervisorName.search('fmi\\mahmed').donefunction (data) {varSupervisorName.add(data[0]);});
}, function () {        });
    });
});

Outcomes