none
How to Read Data in Bindings.AddFromPromptAsync method RRS feed

  • Question

  • Hi I am trying to use the "AddFromPromtAsync" method to bind Data and Read the Data, but it does not seem to be working. My code is as follows:

    function getBindReadReturn() {
        //Create Binding through prompt
        Office.context.document.bindings.addFromPromptAsync(Office.CoercionType.Table, { id: "chartDataBinding" }, function (asyncResult) {
            if (asyncResult.status === "failed") {
                writeToPage('Error: ' + asyncResult.error.message);
            }
            else {
                readBoundData();
            }
        });
    };
    //Read Data from Binding Created
    function readBoundData() {
        Office.select("bindings#chartDataBinding").getDataAsync(Office.CoercionType.Table, function (asyncResult) {
            bindedChartData = asyncResult.value;
            writeToPage(asyncResult.value);
        });
    };
    //Creating the WritingFunction
    function writeToPage(message) {
        document.getElementById("Results").innerText += message;
    }

    It gives me an error after in select data from prompt that says: INCORRECT DATA SOURCE REFERENCE. What is it that I am doing wrong?

    Tuesday, November 5, 2013 2:06 PM

Answers

  • Hi Bongani Zulu,

    Your CoercionType should be “Matrix”; please try the code below:

        function getBindReadReturn() {
            //Create Binding through prompt
            Office.context.document.bindings.addFromPromptAsync(Office.CoercionType.Matrix, { id: "chartDataBinding" }, function (asyncResult) {
                if (asyncResult.status === "failed") {
                    writeToPage('Error: ' + asyncResult.error.message);
                }
                else {
                    readBoundData();
                }
            });
        };
        //Read Data from Binding Created
        function readBoundData() {
            Office.select("bindings#chartDataBinding").getDataAsync(function (asyncResult) {
                writeToPage(asyncResult.value);
            });
        };
        //Creating the WritingFunction
        function writeToPage(message) {
            document.getElementById("Results").innerText += message;
        }

    For more information, please refer BindingType enumeration (apps for Office).


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, November 7, 2013 6:04 AM
    Moderator

All replies

  • >>Office.context.document.bindings.addFromPromptAsync(Office.CoercionType.Table, { id: <<

    Based on the sample from 

    http://msdn.microsoft.com/en-us/library/fp142150.aspx

    Office.context.document.bindings.addFromPromptAsync(Office.BindingType.Text,...

    There are only three types in BindingType

    Please try Office.BindingType.Table




    Wednesday, November 6, 2013 10:19 AM
  • Hi Bongani Zulu,

    Your CoercionType should be “Matrix”; please try the code below:

        function getBindReadReturn() {
            //Create Binding through prompt
            Office.context.document.bindings.addFromPromptAsync(Office.CoercionType.Matrix, { id: "chartDataBinding" }, function (asyncResult) {
                if (asyncResult.status === "failed") {
                    writeToPage('Error: ' + asyncResult.error.message);
                }
                else {
                    readBoundData();
                }
            });
        };
        //Read Data from Binding Created
        function readBoundData() {
            Office.select("bindings#chartDataBinding").getDataAsync(function (asyncResult) {
                writeToPage(asyncResult.value);
            });
        };
        //Creating the WritingFunction
        function writeToPage(message) {
            document.getElementById("Results").innerText += message;
        }

    For more information, please refer BindingType enumeration (apps for Office).


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, November 7, 2013 6:04 AM
    Moderator
  • Jeffrey-Chen and Andy-mic, thank you very much. The matrix binding type works. Much appreciated.

    Bongani Zulu

    Tuesday, November 12, 2013 1:23 PM
  • just to add to this answer, Bingani, its important when to use the Binding Types. your sample would have worked if you tried selecting a table in excel. This may seems obvious but I want to mention it anyways, Its important to differentiate between tables and ranges. tables are a solid concept in Excel (enables you to sort, append items, etc), something not present in regular ranges.

    So basically the idea is you use the table bindings doe selecting tables and the matrix binding for ranges

    Hope this helps  clarify a bit more.

    Thanks!

    Juan.

    Friday, November 15, 2013 6:44 PM
    Moderator