Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Windows USERNAME in Adobe Form?

Avatar

Former Community Member
I am creating a form in LiveCycle. I would like to capture the windows username of the form creator. The following javascript works, but not embedded in my Adobe form. Any advice? Thanks for the help.



var ws = WScript.CreateObject("WScript.Shell");

var un = ws.ExpandEnvironmentStrings("%USERNAME%");

TextField1.rawValue=un;
11 Replies

Avatar

Former Community Member
Ryan,



I was able to pull the username into a path using the script below:



var myPath = app.getPath("user", "documents") + "/AdobeFiles/myDoc.pdf"



This script created a file named myDoc.pdf, in a folder named AdobeFiles within "My Documents".



Good luck.

Pam

Avatar

Former Community Member
Can I put the username in a txt document, then read the txt document using javascript and set the value in my form? Can importTextData be used?



this.importTextData("username.txt",0);

Avatar

Level 7
With folder level JavaScripting one can obtain user's identity as set in Acrobat's or Reader's "Identity" preference when the application starts into an application variable and this variable could then be accessed in any opened PDF. But this requires the addition of a JavaScript file to every user's system.

Avatar

Former Community Member
Thanks Geo! I created a javascript file in Adobe Reader's Javascripts directory which holds those Identity variable. Then I reference it from my form to get the login name.

Avatar

Level 7
If the user completes the other information you can get the Name, Title, Organization Name, Organization Unit (depends on version), and Email address.

Avatar

Former Community Member
Geo (or others),

Is it possible to get an Environment Variable - like the Windows username - using a folder level script similar to Ryan's original example? Could you then pass that variable as the parameter in a SQL statement against a database in a dynamic form? If so, how and what would that look like? Thanks so much...



Chris

Avatar

Former Community Member
Ryan,



Can you post some code you used in LiveCycle to access the identity variable you mention from the javascript code. I could really use that, thanks,

Avatar

Level 7
The folder level JavaScript can be:



// folder level JavaScript to allow access to the identity object properties

// application variable to hold the properties of the identity object

var Identity = new Array();

// loop through the properties of the identity object

for (i in identity) {

// place each property of the identity object into an element of the same name in the Identity array

Identity[i] = identity[i];

}



LiveCycle Designer JavaScripts run on client to access the elements of the Identity array or the properties of the identity object:



// loginName:

$.rawValue = Identity.loginName;



// name:

$.rawValue = Identity.name;



// corporation:

$.rawValue = Identity.corporation;



// e-mail:

$.rawValue = Identity.email;



Acrobat Forms JavaScripts to access the elements of the Identity array or the properties of the identity object:



// loginName:

event.value = Identity.loginName;



// name:

event.value = Identity.name;



// corporation:

event.value = Identity.corporation;



// e-mail:

event.value = Identity.email;

Avatar

Former Community Member
HI Geo,



What do you mean exactly with "folder level javascript"?

gr. tmim

Avatar

Level 7
>What do you mean exactly with "folder level javascript"?



See js_developer_guide.pdf, chapter 3.



Aandi Inston

Avatar

Former Community Member
Hi Geo,



What do you mean with "folder level javascript"?

gr. tmim