13 Replies Latest reply on Oct 22, 2008 6:10 AM by gkaiseril

    Identity.loginName in adobe acrobat 8.0

      Hello,
      I have a very simple folder level JavaScript that was working on Acrobat 7. On 8 it does not work. Is there any setting or Approach that will make this work? The script is to set the loginName from identity to global variable that will be used when document is printed. I have tried using trusted function and get the same error. thanks Kumud

      Javascript that does not work
      global.myname = identity.loginName;
      global.setPersistent("myname", true);
      Or
      getLoginName = app.trustedFunction( function ){
      var myLoginName= "";
      app.beginPriv();
      myLoginName= identity.loginName;
      app.endPriv();
      return myLoginName;
      }
      global.myname = getLoginName;
      global.setPersistent("myname", true);

      Error I get is:
      NotAllowedError: Security Settings prevent access to this property or method.
      Identity.loginName:1:Folder-Level:App:glob.js
        • 1. Re: Identity.loginName in adobe acrobat 8.0
          Bernd Alheit Adobe Community Professional & MVP
          Try this:

          getLoginName = app.trustedFunction( function (){
          var myLoginName= "";
          app.beginPriv();
          myLoginName= identity.loginName;
          app.endPriv();
          return myLoginName;
          }
          );
          • 2. Re: Identity.loginName in adobe acrobat 8.0
            Level 1
            Thank you. I just tried it gives me same error.
            • 3. Re: Identity.loginName in adobe acrobat 8.0
              Bernd Alheit Adobe Community Professional & MVP
              Try this:

              global.myname = getLoginName();
              • 4. Re: Identity.loginName in adobe acrobat 8.0
                Level 1
                Still no luck. Gives same error as before.
                • 5. Re: Identity.loginName in adobe acrobat 8.0
                  Bernd Alheit Adobe Community Professional & MVP
                  What is the exact content of glob.js.
                  • 6. Re: Identity.loginName in adobe acrobat 8.0
                    Level 1
                    getLoginName = app.trustedFunction( function (){
                    var myLoginName= "";
                    app.beginPriv();
                    myLoginName= identity.loginName;
                    app.endPriv();
                    return myLoginName;
                    }
                    );

                    global.myname= getLoginName();
                    global.setPersistent("myname", true);
                    • 7. Re: Identity.loginName in adobe acrobat 8.0
                      gkaiseril MVP & Adobe Community Professional
                      Try this code as a folder level JS function:

                      getIdentity = app.trustedFunction( function (sProperty) {
                      /*
                      Reader/Acrobat JS folder/application level function
                      This function must be established on initialization of the application.

                      Function - Get an identity object from the Reader/Acrobat application
                      Input(s) - string value of the name for the identity property being requested
                      returns - string value of the requested property or 'undefined' if the requested property does not exist
                      */
                      var iProperty = '';
                      app.beginPriv(); // explicitly raise privilege for version 7 & above
                      iProperty = identity[sProperty]; // get the requested property
                      app.endPriv();
                      return iProperty; // return the property or 'undefined' for nonexistent property
                      })
                      // end of folder/application level function

                      // examples of use through the JS console or debugger
                      console.show(); // open JS console
                      console.clear(); // clear JS console

                      var sIdentity = ''; // define a string for an identity propriety

                      // get the 'corporation' property
                      sIdentity = getIdentity("corporation")
                      console.println("corporation: " + sIdentity);

                      // get the 'email' property
                      sIdentity = getIdentity("email")
                      console.println("email: " + sIdentity );

                      // get the 'loginName' property
                      var sIdentity = getIdentity("loginName")
                      console.println("loginName: " + sIdentity );

                      // get the 'name' property
                      var sIdentity = getIdentity("name")
                      console.println("name: " + sIdentity );

                      It is more generalized to allow obtaining any identity property. And it works with forms created by LiveCycle Designer.
                      • 8. Re: Identity.loginName in adobe acrobat 8.0
                        Level 1
                        Geo, I copied you code as is and get this error on console

                        NotAllowedError: Security Settings...
                        App.trustedFunction:1:Folder-Level:App:glob.js
                        • 9. Re: Identity.loginName in adobe acrobat 8.0
                          gkaiseril MVP & Adobe Community Professional
                          Try the code in another file. And to get the code to be active, you will have to restart Acrobat.

                          Not only do you need to build a trusted function to access the 'identity' object, you also need to use the trusted function with the 'global' object.

                          "global This is a static JavaScript object that allows you to share data between documents and to have data be persistent across sessions. Such data is called persistent global data. Global data-sharing and notification across documents is done through a subscription mechanism, which allows you to monitor global data
                          variables and report their value changes across documents.

                          Note: Beginning with version 8.0, the access to global variables has changed somewhat, the details aredescribed below:

                          The JavaScript category in the Preferences dialog box (Ctrl + K) has a new security check box: Enable Global Object Security Policy.

                          ● When checked, the default, each time a global variable is written to, the origin which set it isremembered. Only origins that match can then access the variable.

                          ● For files, this means only the file that set it, having the same path it had when the variable was set, can access the variable.

                          ● For documents from URLs it means only the host which set it can access the variable.

                          There is an important exception to the restrictions described above, global variables can be defined and accessed in a privileged context, in the console, in a batch sequence and in folder JavaScript. For more information on privileged contexts, see Privileged versus non-privileged context on page 32.

                          ● When not checked, documents from different origins are permitted to access the variable; this is the behavior previous to version 8.0.

                          For examples, see section Global object security policy on page 480."
                          • 10. Re: Identity.loginName in adobe acrobat 8.0
                            Level 1
                            I did an uninstall and reinstall just to make sure and still the problem is there. The problem happens immediately as the javascript is executed and the code starts to do an app.trustedFunction call, so my suspicion is that there is something on the registry or something that is preventing this. Any idea?
                            • 11. Re: Identity.loginName in adobe acrobat 8.0
                              gkaiseril MVP & Adobe Community Professional
                              Have you tried the sample console scripts in the console or in a button?

                              // examples of use through the JS console or debugger
                              console.println("Product & Version: " + app.viewerType + " " + app.viewerVersion);
                              // show JS folder locations
                              console.println("Applicaton JS folder: " + app.getPath("app", "javascript") );
                              console.println("User JS folder: " + app.getPath("user", "javascript") );

                              // loaded function
                              console.println(getIdentity);

                              var sIdentity = ''; // define a string for an identity propriety

                              // get the 'corporation' property
                              sIdentity = getIdentity("corporation")
                              console.println("corporation: " + sIdentity);

                              // get the 'email' property
                              sIdentity = getIdentity("email")
                              console.println("email: " + sIdentity );

                              // get the 'loginName' property
                              var sIdentity = getIdentity("loginName")
                              console.println("loginName: " + sIdentity );

                              // get the 'name' property
                              var sIdentity = getIdentity("name")
                              console.println("name: " + sIdentity );

                              console.println('end of test script');

                              Product & Version: Exchange 7.1
                              Applicaton JS folder: /C/Program Files/Adobe/Acrobat 7.0/Acrobat/JavaScripts
                              User JS folder: /C/Documents and Settings/userid/Application Data/Adobe/Acrobat/7.0/JavaScripts

                              function (sProperty) {
                              var iProperty = "";
                              app.beginPriv();
                              iProperty = identity[sProperty];
                              app.endPriv();
                              return iProperty;
                              }

                              corporation: Employer Name
                              email: user.Xxxxxx@example.com
                              loginName: userX
                              name: George Xxxxxx
                              end of test script

                              undefined

                              And you do have the folder level code installed in one of Acrobat's/Reader's JavaScript appliction folders, either the application or user.
                              • 12. Re: Identity.loginName in adobe acrobat 8.0
                                This looks more of a setting related issue rather than a code issue.
                                I have been facing similar issues.
                                The GetLoginName() does not return any value to me.

                                however the same thing returns the expected value on other pages. Problem is i thought it was something related to access rights but then i realized this is also used in another file in the same folder.
                                • 13. Re: Identity.loginName in adobe acrobat 8.0
                                  gkaiseril MVP & Adobe Community Professional
                                  I think you really need to read the Acrobat JavaScript Reference. The whole "trustedFunciton()" and the privilege is the result of security issues. Prior to version 6 one only needed to reference the identity object and property.

                                  The provided function code, "getLoginName" or "getIdentity", needs to be placed in the Acrobat/Reader JavaScript file on the client/user computer or run through the JS console or the code will not work. Or one can have the PDF certified so the code can be run within the PDF. Then the function calls should work.