Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Detecting a Change Anywhere in the Form after Opened

Avatar

Level 9

Is it possible to script to detect if any change occurred since the form was opened? For example if one of the text objects now has different text or no text or if a check box is now unchecked or a dropdown slection has changed?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Don,

Not sure if its the forum or not but you need a double equals,

if(event.target.dirty == true){

or, just leave the == true off

if(event.target.dirty){

Bruce

View solution in original post

7 Replies

Avatar

Level 10

Hi,

You should be able to use the dirty property of the Doc object, so

event.target.dirty

Regards

Bruce

Avatar

Level 9

Hello Bruce,

Sorry - I don't know what you mean. I want to beable to detect a change to any object on the form after the form is opened. So for example, have a text field object with a script that states if a change is made to any of the objects on the form, this text field's rawValue will equal "Changed".

So would I put your script in the Form docReady event? Something like this?

if(event.target.dirty){

textField.rawValue = "Changed";

}

Thank you for your help with this.

-Don

Avatar

Level 10

Hi Don,

I think you will need to do this in the preSave event.  The dirty flag is a per session thing, I guess it is what drives the "Do you want to save changes to ... before closing" message if you attempt to close a form without saving the changes.

So the dirty flag is always false at docOpen.

Will you need to reset the textField if the user changes the form values back to the original values (or blanks them out)?

Bruce

Avatar

Level 9

Bruce,

What I plan to use this for is updating the connected database. When the form is closed, if there have been any changes to the form, the form data is exported to the database; updating the database to match the form. If no changes have occurred since the form was opened, no export to the database occurs.

As far as your question if the user makes a change and then outs it back to the original value, reste the textField would be great but not absolutely necessary. The database data would still match the form.

Using the PreSave event seems to make sense so i will do some testing to see if I can get it to work.

I will mark your answer correct as soon as i can get this test done. Thank you for your help with this project.

Avatar

Level 9

Bruce,

I guess I still don't know how to write this script. Is it something like this?

Form1:preSave - (JavaScript, client)

if(event.target.dirty = true){

Subform2.textfield2.rawValue = "Changed";

}

And I can reset the textField2 to blank each time the form is opened.

I can't get this to work. What am I missing?

Avatar

Correct answer by
Level 10

Hi Don,

Not sure if its the forum or not but you need a double equals,

if(event.target.dirty == true){

or, just leave the == true off

if(event.target.dirty){

Bruce