none
Reg: Office.js word load parentContentControl RRS feed

  • Question

  • hi,

    i am using office js api for word, and was trying the below code, the use case is like, i have content control in word which can be nested or not. so i tried the following code, it always throws exception , seem that if parent control is null, but in documentation it says, it will return null if found empty, not sure if its a bug? any suggestion

     Word.run(function (context) {
               
                // Create a proxy object for the content controls collection.
                var contentControls = context.document.contentControls;
    
                // Queue a command to load the content controls collection.
                contentControls.load('text,parentContentControl');
    
          
                return context.sync().....

    thanks

    Vimal


    regards Vimal

    Wednesday, April 13, 2016 3:42 AM

Answers

  • Hi Vimal,

    >>it always throws exception , seem that if parent control is null, but in documentation it says, it will return null if found empty

    Which error you got? I try the code below to get parent control, and I got error “Unable to get property 'parentContentControl' of undefined or null reference”. If I change parentContentControl to type, it worked correctly.

    function getContentControl() {
            Word.run(
                function (context) {
                    //var contentControls = context.document.contentControls;
                    //context.load(contentControls, 'text');
                    var c = context.document.contentControls.getByTag('test2');
                    context.load(c, 'parentContentControl');
                    //context.load(c, 'type');
                    return context.sync().then(function () {
                        app.showNotification(c.items[0].parentContentControl);                   
    
                    });
                })
                .catch(function (error) {
                    app.showNotification('Error: ' + JSON.stringify(error));
                    if (error instanceof OfficeExtension.Error) {
                        app.showNotification('Debug info: ' + JSON.stringify(error.debugInfo));
                    }
                });
           
        }
    

    For this issue, I suggest you submit a feedback in the link below:
    http://officespdev.uservoice.com

    Best Regards,

    Edward


    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.


    Wednesday, April 13, 2016 9:57 AM
    Moderator

All replies

  • Hi Vimal,

    >>it always throws exception , seem that if parent control is null, but in documentation it says, it will return null if found empty

    Which error you got? I try the code below to get parent control, and I got error “Unable to get property 'parentContentControl' of undefined or null reference”. If I change parentContentControl to type, it worked correctly.

    function getContentControl() {
            Word.run(
                function (context) {
                    //var contentControls = context.document.contentControls;
                    //context.load(contentControls, 'text');
                    var c = context.document.contentControls.getByTag('test2');
                    context.load(c, 'parentContentControl');
                    //context.load(c, 'type');
                    return context.sync().then(function () {
                        app.showNotification(c.items[0].parentContentControl);                   
    
                    });
                })
                .catch(function (error) {
                    app.showNotification('Error: ' + JSON.stringify(error));
                    if (error instanceof OfficeExtension.Error) {
                        app.showNotification('Debug info: ' + JSON.stringify(error.debugInfo));
                    }
                });
           
        }
    

    For this issue, I suggest you submit a feedback in the link below:
    http://officespdev.uservoice.com

    Best Regards,

    Edward


    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.


    Wednesday, April 13, 2016 9:57 AM
    Moderator
  • This is Microsoft Office word 2016 version issue. Same code working fine in 16.0.7571.7095. but not working other word 2016 version.

    i have tried document.getSelection().parentContentControlOrNullObject but still getting error:Error:

    Unable to get property '_objectPath' of undefined or null reference.


    • Edited by Keyur.Patel Tuesday, January 31, 2017 11:56 AM Change content
    Tuesday, January 31, 2017 11:51 AM