form global variable cannot update between session

PlanetSong 22-08-2016

Hello, I set a global variable, isFormSaved, to denote that the form is ever saved. Its default value is false.

in the form postSave event:

isFormSaved.value = "true"; // i also tried isFormSaved.value = true

in the form init event:

if(isFormSaved.value=="true")// i also tried isFormSaved.value = true


When the form is first time open, isFormSaved is false. In the postSave event, it's changed to true. But when the form is reopened, init form event still shows it's false.

I use the reader extension to enable "add delete and change from fields".

Anyone has any idea? thank you.

Mark Solution

Are these answers useful?
Help other community members by marking useful answers as accepted.

Accepted Solutions (0)

Answers (11)

Answers (11)



my suggestion: You check the filed metadata to determine if the file hase been saved since it was created.

//Retrieve the creation and modification dates from the forms metadata

var dateCreate = parseInt( Date.parse(['CreationDate'].toString() ) ),

  dateMod = parseInt ( Date.parse(['ModDate'].toString() ) ),

  allowedDifference = 60 * 1000, //allow one minute after creation to apply Reader Extensions to form


xfa.resolveNode("#subform.Textfield1").rawValue = null;

// If creation date and modification date are identical, the file has never been saved since creation

if (dateCreate === dateMod) {

  hasBeenSaved = false;

// If creation date and modification date are different, the file has been saved since creation

} else {

  //If the difference in less than the allowed difference above, still treat the form as it has not been saved before

  if (dateCreate >= (dateMod - allowedDifference) ) {

  hasBeenSaved = false;

  } else {

  hasBeenSaved = true;



xfa.resolveNode("#subform.Textfield1").rawValue = hasBeenSaved === false ? "unsaved" : "saved";

Hope this helps!

Note: When you update the form in Designer, use "Save As…" instead of "Save" to save the form. Otherwise the creationDate won't get updated!

PlanetSong 24-08-2016

OK indeed we may need a new thought.... Let me explain the requirement to you.

We need to do validation on a form, and pop up alert box if any field is invalid. but if the user is given an empty form, there's no need to do the validation.

Initially I post the thread to ask for help on how to check one form is empty without any input. The problems are, the form might have some default values/ no one responses.

My teammate suggests me I can try to capture if this form is ever saved, so I modified this post and now with you reading my latest thread. There's a problem about presave event, "And in the case you put the flag change on preSave you can't be entirely sure that the save process won't be cancelled... " says mattiaswallin


Why do you use the postSave event? This makes no sense to me, as it fires only after the changes have been saved.

Use the preSave event instead.

PlanetSong 23-08-2016

Hello Radzmar, I've come across several of your tutorials and forum answers during development! nice to meet you!

i've tried both ways, a global var or a hidden fields. i update its value at postSave event, but according to mattiaswallin, "it will disappear until the next time you open as you don't save the form after that change have had happened. " so we are in a dilemma...


It looks like you're tying to manipulate a variable you defined under the form properties, right?!

This won't work, because this variables are located in the forms template which is read only at runtime.

But, you can use a hidden form field instead.

PlanetSong 23-08-2016

hi there, what do you mean by a "field flag" on presave event?

yes indeed the save event may be cancelled.

so seems we are both getting lost..

mattiaswallin 22-08-2016

Oh right, that would be a problem then as you set the value of that field in the postSave event. The value of the field will be changed, but it will disappear until the next time you open as you don't save the form after that change have had happened. In that way you could probably only use a "field flag" on the preSave event, so that the changes will be preserved.

And in the case you put the flag change on preSave you can't be entirely sure that the save process won't be cancelled... And then we are back at your original problem

PlanetSong 22-08-2016

Hi there, i tried with your solution, set its value at its postSave event, but I don't set its value at other events. Still at next open of the form, its value is null.

Still something wrong.

mattiaswallin 22-08-2016

I honestly have no clue how LiveCycle deals with global variables on opening/closing of forms.

I know one way of achieving the functionality you're looking for anyhow is having an invisible "flag" field. Meaning simply using a numeric field and have its presence as hidden. Then you can toggle its .rawValue between 0 and 1 and use that as a true/false flag for if your form have been saved.

However I'm not sure if this is the answer you are looking for. But it's something