These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to Capture UserID and Add to Form

aguedry
Registered: Feb 4 2009
Posts: 3

Hello,
New to the forum and also new to LiveCycle Designer. Am attempting to create a form that when opened, would autopopulate the user's id into a text box and can't seem to find out how to do it. Can anyone help me out?

Thanks
Angie

My Product Information:
LiveCycle Designer, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Because of a security restriction of Acrobat, you will need to creaate a folder level JavaScript that can capture or create a trusted function to provide this data.

As documented in Adobe's Acrobat JavaScripting Manual, there are security restrictions with respect to the "identity" object. Those restrictions prevent one from directly accessing the "identity" object from a form field. You can access the properties from a folder level JavaScript. The following script when placed in Acrobat's application JavaScript folder will create and initialize application level variables that be accessed by any PDF opened by Acrobat:

// Folder level script to create an application level variables for the "identity" objects properties
var Identity = new Array();
Identity.Corporation = identity.corporation;
Identity.Email = identity.email;
Identity.LoginName = identity.loginName;
Identity.Name = identity.name;

// or
var Identity = new Array();
for (i in identity)
Identity.i = identity.i;



One can then add the following document level or field level javaScript to initialize fields within the PDF to the value of the application level variables:

this.getField("loginName").value = Identity.LoginName;
this.getField("name").value = Identity.Name;
this.getField("by").value = "By: ";
this.getField("by").value += Identity.Name;


With version 7.0 or above, you can use a trusted function located as a document level script to retrieve the information:

trustedIdentity = app.trustedFunction( function (sProperty) {
var iProperty = "";
app.beginPriv(); // explicitly raise privilege
iProperty = identity[sProperty];
app.endPriv();
return iProperty;
})

One can then add the following document level or field level javaScript to initialize fields within the PDF to the value of the application level variables:

this.getField("loginName").value = trustedIdentity("loginName");
this.getField("name").value = trustedIdentity("name");
this.getField("by").value = "By: ";
this.getField("by").value += trustedIdentity("name");


You can find the folders for application folder JavaScripts with:

app.getPath("app","javascript");
app.getPath("user","javascript");

George Kaiser

m1ketayl0r
Registered: Jul 14 2010
Posts: 1
gkaiseril wrote:
With version 7.0 or above, you can use a trusted function located as a document level script to retrieve the information:trustedIdentity = app.trustedFunction( function (sProperty) {
var iProperty = "";
app.beginPriv(); // explicitly raise privilege
iProperty = identity[sProperty];
app.endPriv();
return iProperty;
})

One can then add the following document level or field level javaScript to initialize fields within the PDF to the value of the application level variables:

this.getField("loginName").value = trustedIdentity("loginName");
this.getField("name").value = trustedIdentity("name");
this.getField("by").value = "By: ";
this.getField("by").value += trustedIdentity("name");
I'm a complete newcomer to scripting, but I'm trying to create a PDF form in LiveCycle Designer ES, where users tick off items on a checklist, and then a script records who ticked the items and when.

I've tried adding the trustedIdentity function as shown above to the form's docReady function (is that what you mean by a document level script?), but I'm still getting this:

NotAllowedError: Security settings prevent access to this property or method.
App.trustedFunction:1:XFA:form1[0]:docReady

I think that this will only work if I *also* have the folder-level script in place, but using folder level scripts isn't practical, as the form needs to be distributed to a number of users.

Is it just not possible to have a simple document-level script which will retrieve current user information (or at least identify the current user in some way)?

I guess I could add some UI to the form which requires people to enter their initials before completing the form, but that leaves the form open to misuse (people could enter someone else's initials etc).

Any thoughts?

Mike
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
As George said before, you need a folder level script.
There is really no other solution for.

By the way:
If you want to distribute your form to a number of users together with a folder level script, you can design a small installer with the freeware Inno Setup for example.
I have posted an example for this purpose:
[url]http://thelivecycle.blogspot.com/2010/07/create-installer-for-forms-and-scripts.php[/url]

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The Acrobat JavaScript API Reference is pretty clear about the restrictions around this item.

Quote:
[color=red]Note:[/color] The identity object properties are only accessible during [b]batch, console and application initialization events[/b] to protect the privacy of the user. See “Privileged versus non-privileged context” on page 32 for details.
So the error message is telling you that you can not use that code withing the form. You need to have the code run at the [b]initialization[/b] of Acrobat/Reader if you want to use the code within a form.

The application folder level function or variables can be used by AcroForms (forms created in Acrobat) or LiveCycle Designer created forms.

For more information about the trusted function see [url=http://www.acrobatusers.com/tutorials/2008/10/using_trusted_functions]Using Trusted Functions[/url] by Thom Parker.

Adobe has implemented these restrictions since the identity object items can provide more personal data or operating information that has become more sensitive with identity theft and system break ins.

George Kaiser

nikhil_saxena
Registered: Mar 10 2011
Posts: 2
Hello,
I am new to the Adobe Form. The requirement is when user clicks the Button on Adobe Form I have to capture the Windows creditial (i.e Only UserName). I have tried below trustedFunction in the click event of the button.

getUserName = app.trustedFunction(
function(){
app.beginPriv();
var re= identity.name;
app.endPriv();
return re;
}
)

var v_user = getUserName();
app.alert(v_user);


The variable v_user has to return the user name, but I am getting error “NotAllowedError: Security settings prevent access to this property or method.”

Could you please guide me how to use trusted function OR is there any other way to get the user information.

I am using Adobe Livecycle Designer v8.2 and Adobe Reader 9.0.

Nikhil


gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
The 2 scripts I provided can only be in one of the application JavaScript folders for Acrobat/Reader!. .They can not be placed any where else!. .The function can not be part of the script for the button on the form, the function can not included in any document level script or action. .
identity object.
Privileged versus non-privileged context
trustedFunction
app.getPath method.
.

Application initialization actions are only available in a script file located in one of the application's JavaScript folders.


For more information about the trusted function see Using Trusted Functions by Thom Parker.

George Kaiser

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1876
You can retrieve the identity properties with code in the document if you create a certified document. Your users would have to add you to their list of trusted identities and enable high privilege JavaScript for it to work, however. If you do this, the code does not need to be in a trusted function or between app.beginPriv/app.endPriv statements.

So your choice is to get your users to trust you enough to install a JavaScript file on their system that contains privileged code (that any PDF could potentially access), or trust your digital certificate to allow privileged code within a file that you've certified.
nikhil_saxena
Registered: Mar 10 2011
Posts: 2
Hi George,

Thanks for your clarification for issue related to retrieve the username by using trustedFunction.

Here I have any query. Please guide me how to use app.getPath("app","Javascripts") and app.getPath("users","Javascripts") function in adobe form to get the javascripts path with all the version of the adobe.

eg. C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Javascripts\
C:\Program Files\Adobe\Reader 9.0\Reader\Javascripts\

Please let me know what code I have maintain in .js file in javascript folder and what code I have to use in adobe form to get the path.

Regards
Nikhil