4 Replies Latest reply on Mar 24, 2011 1:48 PM by Flying Skwerl

    Making a trusted function for a Dialog?

    Flying Skwerl

      My goal is to create a set of app-level scripts to automate common report generation tasks.  I want a dialog to collect file paths and page numbers for various assets to be manipulated.  The user provides the inputs, hits OK, and the script flies.

       

      My problem:  SECURITY.

       

      Calling app.browseForDoc() throws a security error!  I'm new to the Acrobat object model and it's security model.  I'm having trouble wrapping my brain around the documentation on it.

       

      Can someone give a look the sample of code below and point me in the right direction?

      var dialogAutoReport = {
          initialize: function (dialog) 
          {
              //INSERT CODE TO INITIALIZE DEFAULTS HERE
          },
          commit: function (dialog) 
          { 
              var results = dialog.store();
      
              console.println("Running report " + results["te1"]);
          },
          btn1: function (dialog)
          {
              console.println("Browse button pressed!");
              app.beginPriv();
              var oBrowseResult = app.browseForDoc();
              app.endPriv();
              if (typeof oBrowseResult != "undefined") 
              {
                  dialog.load({ txe1: oBrowseResult.cPath});
              }
          },
          description:
          {
              name: "autoReport",
              align_children: "align_left",
              width:  400,
              height: 400,
              elements:
              [
                  {
                      type: "cluster",
                      name: "Designations",
                      align_children: "align_left",
                      elements:
                      [
                          {
                              type: "view",
                              align_children: "align_row",
                              elements:
                                  [
                                      {
                                          type: "static_text",
                                          name: "Base Report: "
                                      },
                                      {
                                          type: "edit_text",
                                          item_id: "txe1",
                                          alignment: "align_fill",
                                          width: 300,
                                          height: 20
                                      },
                                      {
                                          type: "button", 
                                          item_id: "btn1",
                                          name: "Browse",
                                          alignment: "align_center",
                                          width: 50,
                                          height: 20
                                      }
                                  ]
                          },
                          {
                              alignment: "align_right",
                              type: "ok_cancel",
                              ok_name: "Ok",
                              cancel_name: "Cancel"
                          }
                      ]
                  }
              ]
          }
      };
      
      app.execDialog(dialogAutoReport);
      
        • 1. Re: Making a trusted function for a Dialog?
          George_Johnson MVP & Adobe Community Professional

          Try creating a separate trusted function in the folder-level JavaScript file and call that function in the dialog code. This function would execute the browseForDoc and return the result.

          1 person found this helpful
          • 2. Re: Making a trusted function for a Dialog?
            Flying Skwerl Level 1

            Thank you for the response, sir, I appreciate you stepping me through these basic concepts.

             

            I attempted to create a trusted function on the root of this script and received an error.

             

             

            Here is the error:

            NotAllowedError: Security settings prevent access to this property or method.Error()@:0
            trustedBrowseForDoc()@Console:Exec:4
            ([object ADMDialog])@Console:Exec:26
            execDialog([object Object])@:0
            @Console:Exec:84

             

            Here is my code:

            function trustedBrowseForDoc()
            {
                console.println("trustedBrowseForDoc called");
                var oResult = app.browseForDoc();
                return oResult;
            };
            
            app.trustedFunction(trustedBrowseForDoc);
            
            
            var dialogAutoReport = {
                initialize: function (dialog) 
                {
                    //LOAD DEFAULTS
                },
                commit: function (dialog) 
                { 
                  // called when OK pressed
                    var results = dialog.store();
                  
                  // now do something with the data collected, for example,
                    console.println("Running report " + results["te1"]);
                },
                btn1: function (dialog)
                {
                    var oResult = trustedBrowseForDoc();
                    if (typeof oResult != "undefined") 
                    {
                        dialog.load({ txe1: oResult.cPath});
                    }
                },
                description:
                {
                    name: "autoReport",
                    align_children: "align_left",
                    width:  400,
                    height: 400,
                    elements:
                    [
                        {
                            type: "cluster",
                            name: "Designations",
                            align_children: "align_left",
                            elements:
                            [
                                {
                                    type: "view",
                                    align_children: "align_row",
                                    elements:
                                        [
                                            {
                                                type: "static_text",
                                                name: "Base Report: "
                                            },
                                            {
                                                type: "edit_text",
                                                item_id: "txe1",
                                                alignment: "align_fill",
                                                width: 300,
                                                height: 20
                                            },
                                            {
                                                type: "button", 
                                                item_id: "btn1",
                                                name: "Browse",
                                                alignment: "align_center",
                                                width: 50,
                                                height: 20
                                            }
                                        ]
                                },
                                {
                                    alignment: "align_right",
                                    type: "ok_cancel",
                                    ok_name: "Ok",
                                    cancel_name: "Cancel"
                                }
                            ]
                        }
                    ]
                }
            };
            
            app.execDialog(dialogAutoReport);
            
            • 3. Re: Making a trusted function for a Dialog?
              George_Johnson MVP & Adobe Community Professional

              Add app.beginPriv/app.endPriv before/after the app.browseForDoc call.

              • 4. Re: Making a trusted function for a Dialog?
                Flying Skwerl Level 1

                Gah, so simple and it is right there in the documentation!  I should've known!

                 

                Your solution worked like a charm, thank you very much!  No doubt I'll be back later with more inane questions!