3 Replies Latest reply: Feb 19, 2016 4:01 PM by Nicole Smith RSS

    Document Extension access Definition.xml Variable

    Eric Shaw

      I am trying to access a variable that I have added to the Definition.xml file through a document extension. I have seen a bunch of examples for Object Extensions but that is not what I need. I've attached an example Extension.

       

      The highlights:

       

      script.js:

       

      Qva.AddDocumentExtension(EXTENSION_NAME, function () {
        var doc = Qv.GetCurrentDocument();
      
        if(doc) {
             var testVar;
      
      
             doc.GetAllVariables(function(vars) {
                  for(var i = 0, len = vars.length; i < len; i++) {
                       if(vars[i].name === "TestValue") {
                            testVar = vars[i].value;
                       }
      
                       if(testVar) {
                            break;
                       }
                  }
      
                  console.log(testVar);
             });
        }
      });
      }
        });
      

       

      Definition.xml:

       

      <?xml version="1.0" encoding="utf-8"?>
      <ExtensionObject Label="ExampleExtension" Path="ExampleExtension" Description="" Type="document">
      <Text Label="TestValue" Initial="" Expression="=OsUser()" />
      </ExtensionObject>
      

       

      the document doesn't have a Layout object that I could find to get the variable from the Definition.xml like done in Object Extensions so I'm not sure how else to get the variable with label "TestValue" if not through the GetAllVariables function.