Profile document and WebQueryOpen question

I have a question in regarding how to use profile document for web.

In my WebQueryOpen event I have the following functions

@SetProfileField

 ("UserProfile";"UserName";"test123");

@Command([ToolsRunMacro]; “testagent”)

It will call my java agent which will write a user name to another field in the profile document. Here’s part of my java code.

Document doc = agentContext.getDocumentContext();

Database db = agentContext.getCurrentDatabase();

Document profile = db.getProfileDocument(“UserProfile”, null);

String testusr = profile.getItemValueString(“UserName”);

if ( testusr.equals(“test123”))

 {

  profile.replaceItemValue("UserFullName","Test User");

 }

else

 {

  profile.replaceItemValue("UserFullName","Unknown");

 }

And in my form I have a computed text field called “Test” that will read the value from the “UserFullName” field.

@GetProfileField(“UserProfile”;“UserFullName”)

The problem was when I first open the form from my browser the “Test” field was blank. But after I did a refresh from the browser the form

was able to display the value “Test User” in the form field.

I guess I am not quit understand exactly how the profile document works in relationship to the WebQueryOpen event. Did I miss something?

Any help or suggestion would be greatly appreciated.