How to obtain the data returned by callCommand?

Hi @Constantine

I have copied our full code. Anything we are doing wrong in the below code. Still we are getting ‘undefined’ only in onCommandCallback . We need to get the currentPage value for doc and ppt and sheet index value for excel. Is there any other way we can get it without using ‘callCommand’ function.

(function (window, undefined) {

	window.Asc.plugin.event_onDocumentContentReady = function () {

         window.Asc.plugin.info.interface = true;
		 window.Asc.scope.editorType = this.info.editorType;
          setInterval(function () {
                  window.Asc.plugin.callCommand(
                      function () {
                        var currentPage = Asc.scope.editorType === 'cell'
                          ? Api.GetActiveSheet().GetIndex()
                          : Api.GetCurrentVisiblePage();
                        console.log('current page audit page', currentPage); // getting currentPage value
                        return currentPage;
                      });
                    window.Asc.plugin.onCommandCallback = function (currentPage) {
                      console.log('Received onCommandCallback audit result:', currentPage);  // GETTING UNDEFINED
                    };
                     
                  },1000);
 };

})(window, undefined);


Thanks,
Jagan B

Are you getting it in specific editor or in all of them?

I’m not also sure what is the point of using setInterval. Please elaborate on this.

We are getting undefined in all editors.

We need to know immediately whenever a page is changed. So we are using ‘setInterval’ to get the currentPage each second. We have tried without ‘setInterval’ too and getting same undefined.

The problem seems to come the line:

        window.Asc.plugin.info.interface = true;

Commenting it out or setting the value to false allows getting currentPage on the callback too.

May I know how do you use it? Also, I wasn’t able to find this parameter in the info object:
https://api.onlyoffice.com/docs/plugin-and-macros/interacting-with-editors/overview/how-to-call-commands/#info-object

Where did you find this parameter?

Hi @Constantine

Thanks for helping us to resolve this issue. Now we are able to get the value in onCommandCallback for doc and excel files. But callCommand function is not executed for Presentation files(ppt) alone if we remove that line.

(function (window, undefined) {

	window.Asc.plugin.event_onDocumentContentReady = function () {

        
		 window.Asc.scope.editorType = this.info.editorType;
          setInterval(function () {
                  window.Asc.plugin.callCommand(
                      function () {
                         console.log("Line executed");  // Not executed for Presentation file

                        var currentPage = Asc.scope.editorType === 'cell'
                          ? Api.GetActiveSheet().GetIndex()
                          : Api.GetCurrentVisiblePage();
                        console.log('current page audit page', currentPage); // Not executed for Presentation file
                        return currentPage;
                      });
                    window.Asc.plugin.onCommandCallback = function (currentPage) {
                      console.log('Received onCommandCallback audit result:', currentPage);  // Undefined for Presentation file
                    };
                     
                  },1000);
 };

})(window, undefined);

I don’t experience this issue with latest version 8.2.2 of Desktop Editors/Document Server with PPT or PPTX files. Which version are you using?

Also I’m not sure why do you use onDocumentContentReady in your scenario, but make sure to add it to variations.events parameter.

We upgraded recently. We are using 8.2.1.38 version. We have added onDocumentContentReady to variations.events parameter in config file.

(function (window, undefined) {
window.Asc.plugin.event_onDocumentContentReady = function () {
        window.Asc.plugin.info.interface = false;   
        window.Asc.scope.editorType = this.info.editorType;
       
       setInterval(function () {
        window.Asc.plugin.callCommand(
            function () {
                console.log('call command IN');      // Not executed for presentation alone. Executing in doc and excel
                var currentPage = Asc.scope.editorType === 'cell'
                ? Api.GetActiveSheet().GetIndex()
                : Api.GetCurrentVisiblePage();
              
             
              return currentPage;
            });
            
          window.Asc.plugin.onCommandCallback = function (currentPage) {
            console.log('Received onCommandCallback audit result:', currentPage);    // Getting undefined for Presentation alone. Working fine in doc and excel
            
          };
           
        },1000);

};

})(window, undefined);

Above is our full code.
If we use window.Asc.plugin.info.interface = true , callCommand function is executed for Presentation, but onCommandCallback is not executed. If we use window.Asc.plugin.info.interface = false or remove the line, callCommand function is not executed for Presentation files.

This is not the latest version, 8.2.2 is. Please update once again.

Also, you code is missing init function which is obligatory to use. Here is my full code that works:

(function (window, undefined) {
    window.Asc.plugin.init = function () {
        window.Asc.plugin.event_onDocumentContentReady = function () {
            // window.Asc.plugin.info.interface = false;
            window.Asc.scope.editorType = this.info.editorType;

            setInterval(function () {
                window.Asc.plugin.callCommand(
                    function () {
                        console.log('call command IN');
                        var currentPage = Asc.scope.editorType === 'cell'
                            ? Api.GetActiveSheet().GetIndex()
                            : Api.GetCurrentVisiblePage();
                        return currentPage;
                    });
                window.Asc.plugin.onCommandCallback = function (currentPage) {
                    console.log('Received onCommandCallback audit result:', currentPage);
                };
            }, 1000);
        };
    }
})(window, undefined);

I’ve also for easier test specified isSystem parameter as true to make plugin autostart and did not experience any issues.

It makes me think that this topic is no longer about callback, but specific issue. Please start a new topic for that if you feel so too.