155
Views
9
Comments
Solved
How to detect whether a value in a field changed from null?
Application Type
Reactive
Service Studio Version
11.53.20 (Build 61431)

Hi, I have a form that has several attributes for user input (it allows users to enter their Dog):

  • Name - Mandatory
  • Breed - Non-mandatory
  • BirthWhen - Non-mandatory

The workflow I am desiring is this: users go into the Details form and create a new Dog record. Users may or may not enter Breed and BirthWhen. Once a Dog record has been created, the user may go into that record detail to edit. 

IF the user originally did NOT supply a value for Breed or BirthWhen, and then they provide a value while editing, I want the information to save no questions asked. Note that the incoming Id for Dog in this case is not null.

IF the user originally DID supply a value for either Breed or BirthWhen, and then they go in and edit those pre-existing values, I would like a "Confirmation Dialog" to appear which asks the user whether they are certain they would like to update the Record information. 

The same goes for Name (if they ever happen to change the value of Name for a given record) - basically, regardless of whether the incoming Id for Dog is null, whenever a given attribute is updated from non-null I want the confirmation dialog workflow.

I've played around with a Boolean variable that would get a "True" value from the OnChange event of the given fields, so that whenever a given value is changed, the confirmation dialog workflow could go into effect when pressing the save button. However, I am not sure how to detect whether the previous value of the given attribute was non-null. The change of the field could be either a change from null or a change from non-null, but I only care about the change from non-null. How can I detect whether the change of the field is from non-null, when the variables for the fields (for example "GetDogById.List.Current.Dog.Breed", etc.) are immediately updated once a new value is selected (in other words, once a value is changed, I don't know what the previous value was anymore)? Do I need a "container" variable that holds this? How would I go about this? 

Thank you!

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho
Solution

Hi Jared,


Right now I think that solution fits your needs:

  • "If the user originally did NOT supply a value for Breed or BirthWhen, and then they provide a value while editing, I want the information to save no questions asked. Note that the incoming Id for Dog in this case is not null.
  • If the user originally DID supply a value for either Breed or BirthWhen, and then they go in and edit those pre-existing values, I would like a "Confirmation Dialog" to appear which asks the user whether they are certain they would like to update the Record information. 
  • The same goes for Name (if they ever happen to change the value of Name for a given record) - basically, regardless of whether the incoming Id for Dog is null, whenever a given attribute is updated from non-null I want the confirmation dialog workflow."


I did some alterations to the logic flow (see below)


See the OML attached.

Let me know if this is what you want and if it's tell me and I'll refactor this action to suit with OutSystems best practices.


Kind regards,

FC

Dogs.oml
2023-10-21 19-42-11
Tousif Khan
Champion
Solution

For that you can just create one more condition and add it to your flow like

In that case just add a aggregate that will  use for your validation purpose it must have a input parameter that will filter the result wrt your DogId whic is passed as a input parameter from your list screen.

GetDogById.List.Current.Dog.Breed = GetDogByIdforValidation.List.Current.Dog.Breed

then on false branch you can pop the message .

Thanks

2023-10-21 19-42-11
Tousif Khan
Champion

Hello,

For the Use case you need to play around with form validation, you can do that client side.

  • The best practice says that we must have CreatedBy, CreatedDate, UpdatedBy, UpdatedDate and IsActive in our Entity when we create database tables.
  • So here you can check in your for by using some condition like, 
    When user is on detail page and Name is already filled but rest fields are null
    GetDogById.List.Current.Dog.Breed = nullTextIdentifier, then your flow will go to True branch of your If widget and the record will be created without any message displayed.
    But if it has some value then your flow will move to False branch and On False branch you can show a message that will ask user that "Are you sure you want to update the data",  something like this message and there You can use a popUp that has two button Yes and No, If the User press Yes the the Fields will be updated,
  • You can define multiple conditions like this and show the message to the user.
  • You can also play around with CreatedDate and UpdatedDate to check conditions according to your requirements.
  • If you want this on a OnChange then in case you can make your save button disable or Hide it using If widget on a screen, I would suggest to hide it, and when the condition is satisfied then only the button will be visible
  • For more security you can apply same validation on save button.

If you need more help let me know,

I hope this can help you

Best Regards

Tousif Khan


2023-02-09 17-26-57
JD136

Hi Tousif, thank you so much! What if I want to parameterize this so that any given field can call the same OnChange event?

I currently have a variable IsChanged, that I've worked out to detect when the kind of change I described above happens. One way I've figured out how to detect this is to have my OnChange event for a given field call the corresponding "Get" method, which in this case would be something like "GetDog(Id).Dog.Breed". I can then see if this original value is equal to my screen aggregate GetDogById.List.Current.Dog.Breed that correlates to the variable of the widget on screen. This works so far if I'm just writing logic for one field, but if I want to have other fields call the same OnChange event (or event fields on other forms in other screens), I run into problems.

My "Save" action:

(YesOnClick is the actual save logic which is tied to the "Yes" button on the confirmation dialog popup.)

The IsChanged variable is set with this logic, which is called in the OnChange event handler for my fields (right now I only have it on one, not all of them):

That GetOriginalRecord2 action goes to the server side and runs the "GetDog(Id).Dog.Breed", but again I would like to parameterize it so that it can run any given action I need from any field anywhere. Thus, I have been playing around with input parameters to this action:

(Right now values are hard-coded, but eventually they would be dynamic and would be specified at the point of OnChange event, not here.)

As you can see I played around with some If logic, but that is rather tedious, not very forward looking, and simply inelegant. I don't know of a built-in method that would convert text into an Action call, but this is what I have:

Do you know how I could convert this passed in text to an Action call?

UPDATE: note that my condition checking whether the current value is different from what it is and that it wasn't previously null looks like this:

(CurrentAttributeValue is the GetDogById.List.Current.Dog.Breed passed in the OnChange event on the screen.) @Fábio Miguel Ferreira Coelho I am studying your OML to see if it works, or could partially help!

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hello Jared,


I hope you're doing well.


To solve your issue I implemented 2 screens and 1 block.

  • Screen Dog List
  • Screen Dog Detail
  • Block Confirmation Message


In the Dog Detail screen, I implemented the logic that suits your conditions when you save a Dog record.

Basically when the "Breed" attribute or the "BirthWhen" attribute are <> "" the confirmation popup appears and you can cancel or accept the changes.


I share the OML file with you.

Let me know if this solves your situation.


Kind regards,

FC

Dogs.oml
2023-02-09 17-26-57
JD136

This is really great as far as the popup aspect goes, much easier than the sweetalert stuff I was looking at (I'll definitely be integrating that into my app)! As far as when the popup appears, it's close but for instance I tried adding a record (a new one) and the popup emerged. I am looking to have the popup appear only when the value entered is different than what it was before, and the value before was non-null.

2023-10-21 19-42-11
Tousif Khan
Champion
Solution

For that you can just create one more condition and add it to your flow like

In that case just add a aggregate that will  use for your validation purpose it must have a input parameter that will filter the result wrt your DogId whic is passed as a input parameter from your list screen.

GetDogById.List.Current.Dog.Breed = GetDogByIdforValidation.List.Current.Dog.Breed

then on false branch you can pop the message .

Thanks

2023-02-09 17-26-57
JD136

Oh that's a really good point. Let me try that out

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho
Solution

Hi Jared,


Right now I think that solution fits your needs:

  • "If the user originally did NOT supply a value for Breed or BirthWhen, and then they provide a value while editing, I want the information to save no questions asked. Note that the incoming Id for Dog in this case is not null.
  • If the user originally DID supply a value for either Breed or BirthWhen, and then they go in and edit those pre-existing values, I would like a "Confirmation Dialog" to appear which asks the user whether they are certain they would like to update the Record information. 
  • The same goes for Name (if they ever happen to change the value of Name for a given record) - basically, regardless of whether the incoming Id for Dog is null, whenever a given attribute is updated from non-null I want the confirmation dialog workflow."


I did some alterations to the logic flow (see below)


See the OML attached.

Let me know if this is what you want and if it's tell me and I'll refactor this action to suit with OutSystems best practices.


Kind regards,

FC

Dogs.oml
2020-08-31 05-04-40
Rahul Jain

Hi ,

Please find attached oml and demo url below 

https://rahul-jain-doitlean.outsystemscloud.com/Example/Dogs

I hope this will help you

Thanks

RJ

Example.oap
2023-02-09 17-26-57
JD136

@Tousif Khan thank you for the suggestion to bring in another aggregate - that worked perfectly as far as checking whether the OriginalValue <> Null and also <> to NewValue. 

@Fábio Miguel Ferreira Coelho thank you for providing the OMLs and particularly the setup with the popup - that's was a major component of what I was looking for and is also what I needed.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.