3

I'm developing a Word Add-in (Word API + Office.js) where i am working with content controls, i am try to check whether control is blank

i am using the below code for this functionality

function callPromise() {

        return new Promise(function (resolve, reject) {
            var MadatoryFieldsList = ["Control1", "Control2", "Control3"];



            $.each(MadatoryFieldsList, function (index, element) {
                Word.run(function (context) {
                    var contentControls = context.document.contentControls.getByTag(element).getFirst();
                    contentControls.load('text');

                    return context.sync().then(function () {
                        var text = contentControls.text;

                        if (text == "") {
                            //document.getElementById('lblMandatory').innerText += element + " is Mandatory" + " ";

                            mandatoryflag = "False";
                        }

                        if (index === MadatoryFieldsList.length - 1) resolve();
                    })


                });


            });

        });

    }

this works fine when i create the content control manually from developer tab in word document ... but if i copy the same from different document or load it from database in the form of OOXML it is not able to fetch the controls.

please let me know if i am missing something

Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Common_Coder
  • 131
  • 6
  • 2
    The Office JS APIs support only ***rich text*** content controls. They won't recognize plain text or other kinds. I'm guessing the controls being copied are plain text... So this should answer your question? [document.contentControls not returning all ContentControls in the document](https://stackoverflow.com/questions/60095160/document-contentcontrols-not-returning-all-contentcontrols-in-the-document) – Cindy Meister Mar 08 '20 at 13:03

0 Answers0