Tech Blog

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

Render PDF Process

Image 1: Render PDF Form Process Design
 

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, parse the query results and assign the values to the correspondent fields. LiveCycle won’t be able to decipher the XPath to the form fields, so you need to know those. However, that should be simple. Just use your main process (where your form variable is defined) and look at the path of your fields) and get your XPath from there. Beware that the xmlData variable of your rendering process matches to the last “data” node of your form variable in the main process. So that your xmlData XPath matches the main process form’s variable XPath like this:

/process_data/xmlData/ = /process_data/[formVarName]/object/data/xdp/datasets/data/
This means that if your form’s fields XPath translates to /process_data/[formVarName]/object/data/xdp/datasets/data/txtFullNameThen, your path translates to /process_data/xmlData/txtFullName  in your rendering process.

5-      Once you have assigned all the values you want to your xmlData variable, you have to inject now this new XML into the input document. If you copied the Render PDF Form, as I mentioned at the beginning, then your input doc var is called inDocData. By assigning the xmlData to the inDocData, LC will know that all you want to do is replace the XML part of the document variable.

 Now that you have pre-populated the input document with the logged in user’s info everything else in the process remains the same. So, your final rendering process should look something like this (See image 2):    

Custom Render PDF Form With User Info Process Design

Image 2: Custom Render PDF Form With User Info Process Design

Remember that on your main process you need to set this as the rendering service for the input form. Once you select this as your rendering service, you’ll notice that the userId variable you set on your rendering service will appear as a “Service Input” variable. Assign the “User’s Id” variable from the “task” to the “userId” input variable. Set the rest of the variables the with the same values as when you use the Render PDF Form service. 

Now, if you initiate your process from the workspace, you’ll get the form pre-populated with the logged in user info. If it doesn’t, read this post again and make sure you understand all the services used here. Also, remember that you can debug your process using the “Variable Logger” service.


9 Comments for this entry

  • John D

    Do you have any more detail on this? I am very new to LCES 8.0 and I am having a tough time getting this to work.

    Thanks in advance!

  • Rolando

    @John,

    I can definitely get into more details. I need to know, however, where is it that you’re stuck at. As I mentioned at the beginning, there are certain things you need to understand before being able to follow this post. I just decided not to get into those details because then this post would be even longer :) I’ll be very glad to help you, just let me know where to start.

  • John D

    Roland,

    Thank you for your time. I am actually stuck at number 2. I think I have a good idea on the rest and have some of those parts built but Number 2 is it right now.

    Thanks in advance!

    John

  • John D

    @Roland,

    Is there any way you could provide me with a .lca file that I could take a look at? I am really under the gun to get this project complete.

    Thanks!!

    John

  • Rolando

    @John,

    To extract the form’s XML data and place it into an XML variable, all you have to do is use the same “SetValue” activity (first activity of the process) and add a list entry that relfeces the following:

    Location = /process_data/xmlData

    Expression = /process_data/@inDocData

    By doing this LiveCycle will know that all you want is the XML part of inDocData variable and will assign it to xmlData.

  • Riccardo

    hi,

    I was wondering are you Rolando Pagunsan Lopez?

    if you are I’m Riccardo D.L. hope you remember me

  • Elaine

    Hi Roland, thanks for this post. Can you provide more detail on the main process? Is it connected to the render process or does your main process only refer to the render process? Thanks

  • bpmuser

    Hi Ronaldo,
    I am able to prepopulate data on the form. however I have a question where I need to get the current user info at every stage..ie., I am getting the originator info by prepoulation, but in stage 2 I need to also get the current user who logged in to the system..Is this possible?
    Hope I iwll get response..
    Thanks in advance!

  • Rolando

    There are different ways you can achieve that, but I think you’re a bit confused here. Normally the initiator is completely unknown until the form is rendered because you have a range of possible users that can login to the system and open the form. After stage one, however you’re using the “Assign Task” this means you somehow need to know the user prior to rendering the form in order to “assign” the task. Therefore, you don’t need to inject the user info at rendering time, but you can do that before the “Assign Task”.

    So, in a nutshell, once the first user submits the form:
    - you get the next user’s info
    - using Xpath you assign the values you want from the next user to the XML data of the form
    - then you use the assign task
    Once the form is rendered the next time it will have the new user’s info.

    This applies to whether you hard-code the user in the assign task or even if you use a variable to dynamically assign the user.

    Hope this helps

    -Rolando

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...