0

EDIT Below works by replacing the success code, not sure if the best solution but it works:

                    success: function (data) {
                    if (data.d != undefined) {
                        $.each(data.d.results, function (index, item) {
                            myFirstName = item.Manager.FirstName;
                            myLastName = item.Manager.LastName;
                            myEmail = item.Manager.EMail;
                            myDivision = data.d.results[0].Title;
                            myPhone = data.d.results[0].PhoneNumber;
                            myJobTitle = data.d.results[0].JobTitle;
                            i++;
                        });
                    }

I'm trying to get information from People or Group column and assign that value to a variable but I keep getting the error alert. How do you pass the value to a variable?

var requestUri = webAbsUrl + "/_api/web/Lists/getByTitle('Organization')/Items?$\
                filter=JobTitle eq 'Deputy Director'&$\
                select=Division, Branch, Section, PhoneNumber, JobTitle, Manager/EMail, Manager/FirstName, Manager/LastName&$\
                expand=Manager/Id";

            var ajaxOrg = $.ajax({
                url: requestUri,
                async: false,  
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: function (data) {
                    countAjaxOrg = data.d.results.length;
                        if(countAjaxOrg > 0) {
                            myJobTitle = data.d.results[0].JobTitle;
                            myPhone = data.d.results[0].PhoneNumber;
                            myFirstName = data.d.results[0].Manager/FirstName;
                            myLastName = data.d.results[0].Manager/LastName;
                            myEmail = data.d.results[0].Manager/EMail;
                            myDivision = data.d.results[0].Division;
                        }
                },
                error: function (data) { alert("Failed to load your profile."); }
            });
0

It looks like you are getting a lot of spaces added to the URL, creating an invalid REST request.

"/_api/web/Lists/getByTitle('Organization')/Items?$                filter=JobTitle eq 'Deputy Director'&$                select=Division, Branch, Section, PhoneNumber, JobTitle, Manager/EMail, Manager/FirstName, Manager/LastName&$                expand=Manager/Id"

Try the following or use string concatenation:

var requestUri = webAbsUrl + "/_api/web/Lists/getByTitle('Organization')/Items?$\
filter=JobTitle eq 'Deputy Director'&$\
select=Division, Branch, Section, PhoneNumber, JobTitle, Manager/EMail, Manager/FirstName, Manager/LastName&$\
expand=Manager/Id";
  • Thanks. I also got it to work after I changed the code inside 'success' I updated my above post with the final code. The error was because I used the display name (Division) rather than the internal name (Title) in select. – Tamras Merin Apr 24 '18 at 21:41

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.