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

How to save a blank exemplar of the current form?

Avatar

Level 3

Is it possible to have a button that performs a "save as" and "reset" without actually resetting the current state?
So literally a button that saves another blank exemplar of the form itself without deleting the current entries.

Thank you in advance

1 Accepted Solution

Avatar

Correct answer by
Level 7

One way to achieve this would be this. In the form's presave event, create variables for all your object values and then reset the form and in the postsave event, restore all the object values from the variables. Presave events take place before the save dialog, postsave event execute after the dialog closes. Note: it will trigger if the user cancels as well.

This will require the creation of global variables. I wrote a bit about global variables here: How to compare global variable value to TextField value

View solution in original post

3 Replies

Avatar

Correct answer by
Level 7

One way to achieve this would be this. In the form's presave event, create variables for all your object values and then reset the form and in the postsave event, restore all the object values from the variables. Presave events take place before the save dialog, postsave event execute after the dialog closes. Note: it will trigger if the user cancels as well.

This will require the creation of global variables. I wrote a bit about global variables here: How to compare global variable value to TextField value

Avatar

Level 3

Great insight MinusZero!

Plus your write up on Global Variables help me piece together a working button.

I don't think my version is the most effective, but it seems to work.

For everyone else interested here's my proof of concept:

1Text Field Object: "Test1"

1 Button Object: "SaveBlank"

Insert a Script Object: "Memory"

Memory

var Test1X = Test1;

Test1

// initialize event //

this.rawValue = Memory.Test1X;

this.rawValue = "";

SaveBlank

// click event //

app.execMenuItem("SaveAs");

//preSave event //

Memory.Test1X.rawValue = Test1.rawValue;

//postSave event //

Test1.rawValue = Memory.Test1X.rawValue;

Soo, type some text in Test1 field. Click on the button. prompts a "save as" window. Save.

Your inputted text remains, but a blank form is saved. Yeah.

Some might be going "hey! you didn't reset the fields."

I say, "yeah... it seems I don't need to.. I don't know really why, but ehh..."

I'm thinking its because I threw in the this.rawValue=""; in the Text Field Object, the strange Test1X = Test1 loopy thing, and order of operations, all happening in a mishaps of desired outcome.

Good luck!

Avatar

Level 7

Great stuff. Sometimes the simplest option is the best. All my code is very uncomplicated, it is larger, but it works which is my desired outcome.