none
How to load data on app initialization? RRS feed

  • Question

  • Hi,

    I wanted to load some initial data on start of my Office Excel task pane app. For this I was trying to make a WCF call from Office.initialize but this does not work and the app does not show up in the task pane. I then tried to call the WCF service from a button click event and it works fine. So is there a way by which I can load the data after app initialization? Here is what I was trying -

     Office.initialize = function (reason) {
            $(document).ready(function () {
                app.initialize();

                $.ajax
                (
                    {
                        type: 'GET',
                        url: 'http://[my service url]/Service1.svc/GetEmp',
                        data: "{}",
                        contentType: "application/json; charset=utf-8",
                        dataType: "jsonp",
                        success: function (response) {
                            success(response);
                        },
                        error: function (err) {
                            fail(err);
                        }
                    }
                );
            });
        };

     Thanks,
    Mayur.

    Friday, April 19, 2013 7:26 PM

Answers

  • Hi Mayur

    Your plan should work - there's no problem with calling functions or services on the callback function from Office.initialize. You're probably running into some other issue with your WCF call. To verify that this is the issue, you could try creating an HTML button that calls a separate function with your WCF call logic in it. If that fails, then the problem doesn't have to do with Office.initialize.

    Also, check that you have loaded jQuery before you use it for the WCF call.

    Let me know if you have more questions. Thanks!

    -Michael

    • Marked as answer by Mayur Parmar Sunday, April 21, 2013 3:32 AM
    Saturday, April 20, 2013 12:02 AM
    Moderator

All replies

  • Hi Mayur

    Your plan should work - there's no problem with calling functions or services on the callback function from Office.initialize. You're probably running into some other issue with your WCF call. To verify that this is the issue, you could try creating an HTML button that calls a separate function with your WCF call logic in it. If that fails, then the problem doesn't have to do with Office.initialize.

    Also, check that you have loaded jQuery before you use it for the WCF call.

    Let me know if you have more questions. Thanks!

    -Michael

    • Marked as answer by Mayur Parmar Sunday, April 21, 2013 3:32 AM
    Saturday, April 20, 2013 12:02 AM
    Moderator
  • There is no need to use

    $(document).ready(function () {
    });

    inside Office.initialize, since initialize method (i think) gets called after the DOM is ready and loaded. Also in my cases i found out, that i get better response if i dont do any ajax calls (makeEwsRequestAsync calls) directly in initialize method, but if i set timeout for it ex.: setTimeout(ajaxCall, 100) . Dont know why, but its something that helped and you might want to try it, if it helps you too.

    Anze Javornik

    Saturday, April 20, 2013 11:04 PM