Archive for March 26th, 2008
Prepopulate Form with Logged in user info in LiveCycle ES
by Rolando on Mar.26, 2008, under LiveCycle ES
I’ve seen several questions in the LiveCycle user forum about how to pre-populate a form with user data in the Workspace, so I’ve decided to demonstrate how to accomplish this. Notice that although this explanation is digested enough so that a beginner can accomplish the task, you need to have a good understanding of how forms are rendered in LiveCycle, basic understanding of the XML Path Language (XPath) & how to set the XML schema to your form.
First let’s understand how LiveCycle renders a form in the workspace for a specific process. When you set your process you set an input variable which holds the form to render. LiveCycle by default assigns the “Default Renderer” service to this variable so that it gets rendered properly in the Workspace. This “Default Renderer” is just a short-lived process with several activities that sets variables and enables your form for the workspace.
If you want to pre-populate a form with data, all you have to do is create your custom renderer service. For instance, let’s say you want to render a PDF form in the Workspace. So we need the “Render PDF Form” (see image 1) from the “Samples Forms” category (this samples should be in your process list unless you/the administrator didn’t upload the LiveCycle Archives that comes with the installation). This process takes a PDF form and renders it to the Workspace. First the short-lived process sets some parameters, then renders the form using the renderPDFForm operation from the Forms Service, and then enables the PDF Form to be rendered in the workspace.

Render PDF Process
To pre-populate the form we need to get the logged in user info and inject that into the form before getting to the “render Form” activity. To do that you can copy the “Render PDF Form” process into a new process. Then to your new process you want to: <more />
1- Add two input variables: one called “userId” of type string and another one xmlData of type xml.
2- In the first step of the process you want to extract the form’s XML data and assign that to the xmlData variable.
3- Then, use the “Query Single Row” operation from the “JDBCService” and query the LiveCycle database to get the user’s info based on the “userId” variable. You can use the LiveCycle’s default datasource which should be “IDP_DS”. Your query will look something like
SELECT canonicalname, commonname, email, organization, address
FROM edcprincipalentity e
WHERE e.id = [xpath to your userId variable]
4- Now that you have the form’s XML data you can assign values to the fields by using XPath. So, (continue reading…)


