Hi I recently made an add-in that displays the upcomming employees's birthday of the company, at the begin all was good, but I don't know why when the people enters for the very fist time of the day the images are not displayed. enter image description here This seems be solved by entering to delve and then comeback.

For this I'm using REST API search, like so:

 var birthday = 'Birthday01';
        var space = '%20';
        var colon = '%3A';
        var quote = '%22';
        var gt = '%3E';
        var lt = '%3C';
        var amp = '&';

        // Get current date
        var currentTime = new Date();
        var startMonth = currentTime.getMonth() + 1;
        var day = currentTime.getDate();

        // Get current date + 30
        var endTime = new Date();
        var endTime = currentTime.AddDays(30);
        var endMonth = endTime.getMonth() + 1;
        var endDay = endTime.getDate();

        var querytext = "";

        // build query with the magic 2000 year
        if (startMonth != '12') {

            querytext += birthday + gt + quote + day + '-' + startMonth + '-' + '2000' + quote;
        else {
            querytext += birthday + gt + quote + day + '-' + startMonth + '-' + '2000' + quote;
        Results.url = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext=%27" + querytext + "%27&sourceid=%27B09A7990-05EA-4AF9-81EF-EDFAB16C4E31%27&selectproperties=%27Title," + birthday + ",Path,PictureURL,Department%27&sortlist=%27" + birthday + ":ascending%27";

the parameter i get for display the image is PictureURL from user's profile properties

enter image description here

So, if somebody can help me to figure out what's happening and how can i fix it, it will be great!!

1 Answer 1


For the original issue is it solved by adding my.sharepoint.com to your trusted site / intranet sites? I.e. (in Chrome) go to Settings -> Show advanced settings -> Change proxy settings -> Security tab add the site to Local intranet.

To avoid having to worry about the image loading from a different domain I tend to use /_layouts/15/userphoto.aspx?size=L&accountname=. This can load the profile image using the current sites domain.

I cant see how you handle the results of the REST API call in your above code but what you would do is add AccountName to your list of selectproperties and then in your results your picture URL would use AccountName:

var picUrl = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/userphoto.aspx?size=L&accountname=" + result["AccountName"]

You can change the size= property to S or M depending on the image size you want. Now you're loading the image using the current sites domain as opposed to going to the my.sharepoint one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.