Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

form global variable cannot update between session

Avatar

Level 3

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

    doSomething();

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.

11 Replies

Avatar

Level 3

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

Avatar

Level 3

indeed a good idea....

anyway, why does livecycle ask us to do so many work arounds....

Avatar

Level 3

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.

Avatar

Level 3

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

Avatar

Level 3

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..

Avatar

Level 10

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.

Avatar

Level 3

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...

Avatar

Level 10

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.

Avatar

Former Community Member

how to use these events and where to find them?

Avatar

Level 3

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

Avatar

Level 10

OK,

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( event.target.info['CreationDate'].toString() ) ),

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

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

  hasBeenSaved;

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!