Hi,
I am having a heck of a time trying to get custom field lookup values using JSOM. I am able to get the entry id for the custom field value but when I try to call ltEntries.getById(entryId) or ltEntries.getByGuid(entryId) an empty object is returned.
The LookupEntryCollection (ltEntries in my case) has all of the entries for the lookuptable and I am able to pull the each entry by calling ltEntries.getItemAtIndex() but I am not able to use getByGuid or getById.
Does anyone have any experience with pulling lookup values by ID with JSOM? If so, what am I doing wrong in the code below?
// Declare a variable to store the published projects that exist // in the current context. var projects; var projContext; var customFields; var customFieldData = []; // Ensure that the PS.js file is loaded before your custom code runs. SP.SOD.executeOrDelayUntilScriptLoaded(GetProjects, "PS.js"); // Get the projects collection. function GetProjects() { // Initialize the current client context. var projContext = PS.ProjectContext.get_current(); // Get the projects collection. projects = projContext.get_projects(); lookupTables = projContext.get_lookupTables(); // Register the request that you want to run on the server. // This call includes an optional "Include" parameter to request only the // Name, CreatedDate, and Id properties of the projects in the collection. projContext.load(projects, 'Include(Name, CreatedDate, Id, CustomFields, IncludeCustomFields, FieldValues)'); projContext.load(lookupTables); // Run the request on the server. projContext.executeQueryAsync(onQuerySucceeded, onQueryFailed); } function onQuerySucceeded(sender, args) { projContext = PS.ProjectContext.get_current(); var lookupTable = lookupTables.getByGuid('16216553-dbea-4770-b7cd-5f565ebea160'); var ltEntries = lookupTable.get_entries(); projContext.load(ltEntries); //'Include(FullValue)' projContext.executeQueryAsync(function () { var lookupEnumerator = ltEntries.getEnumerator(); while (lookupEnumerator.moveNext()) { var entry = lookupEnumerator.get_current(); projContext = PS.ProjectContext.get_current(); projContext.load(entry, "FullValue") } projContext.executeQueryAsync(function () { // Get the enumerator and iterate through the collection. var projectEnumerator = projects.getEnumerator(); while (projectEnumerator.moveNext()) { var project = projectEnumerator.get_current(); businessOrgFld = project.get_customFields().getByGuid("a2a72e91-2760-42b7-b20a-0f44f610d6c3"); // Create the row for the project's information. var row = tblProjects.insertRow(); row.insertCell().innerText = project.get_name(); row.insertCell().innerText = project.get_createdDate(); row.insertCell().innerText = project.get_id(); var fieldValues = project.get_includeCustomFields().get_fieldValues(); var enumerator = project.get_customFields().getEnumerator(); while (enumerator.moveNext()) { var customField = enumerator.get_current(); if (customField.get_name() == "Business Organization") { var entryId = fieldValues[customField.get_internalName()]; var lookupEntry = ltEntries.getById(entryId); row.insertCell().innerText = lookupEntry.get_fullValue(); } } } } , onQueryFailed); }, onQueryFailed); } function onQueryFailed(sender, args) { $get("spanMessage").innerText = 'Request failed: ' + args.get_message(); }