Skip to main content
edited tags
Link
Lee
  • 4.3k
  • 1
  • 8
  • 7
Source Link
Jihen
  • 513
  • 3
  • 22

Set the chosen drop down list with lookup field value

This is my Function :

function RetrieveNewChange(ChangeID) {
var getItemsUrl = "/_api/Web/Lists/GetByTitle('" + ChangeList + "')/items?$select=ID,Title,Employee/Id,Employee/Title,Employee/FullName&$expand=Employee&$filter=(ID eq " + ChangeID + ")";
var promise = $.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + getItemsUrl,
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {
        console.log(data.d.results);


        if (data.d.results.length > 0) {
            var ArrayRetrieved = data.d.results[0];
            console.log(ArrayRetrieved);

            $('#lookup option[value="' + ArrayRetrieved.Employee.FullName + '"]').prop('selected', true)
            $("#lookup").trigger("chosen:updated");

        }
    },
    error: function (error) {
        console.log("Error on Retrieve Change");
        console.log(JSON.stringify(error));
    }
});
}

But it don't work! I dont get the "ArrayRetrieved.Employee.FullName" value in the dropdown list! Please help.