Hi all,
I am working on this app that allows users to make change requests. In a form, they can select an application through dropdown, if relevant.
Admins can edit the change request after it has been submitted. As part of that, they can also edit the value for the application, if necessary. The dropdown admins use for this is also part of a form.
However, the validation of the dropdown does not do what I expect.
The logic looks like this:
The condition of the IF statement is GetIdeaById.List.Current.Application.Is_Active
Which corresponds to the value variableof the dropdown GetIdeaById.List.Current.Idea.ApplicationId
The assign contains a dropdown.valid = false and a dropdownvalidationmessage = "message" for my application dropdown.
What happens by using this logic is that an error always occurs when an Inactive application has been chosen as application. (This can happen for older ideas that selected an application that has since been made inactive.) However, the error means that the application cannot be updated and therefore other edits in the form cannot be saved either.
Also, when you edit the form that contains an application that is still active, it is always saved, regardless of whether of not the new value is an active or inactive application. The error does never show. Of course, once an inactive application has been chosen, the above happens and it cannot be edited again.
From what happens, I suspect my IF statement looks at my database values, while I want the validation to apply to chosen runtime values. How do I validate the runtime value of my application-dropdown?
Thank you in advance.
Hoi Danique,
let's first see if I'm getting the aim of your validation : it is not allowed to make requests on non-active application ? So
what do you want when admin updates an old request, for an application that is no longer active ? can he update other things while leaving the old application there, or is he forced to choose an active application istead ?
what if an old request was mistakenly attached to the wrong application, admin wants to correct this, but the right application has since been made inactive (active in the past, no longer active now). he is forced to choose an active application instead ?
What you are doing now, is letting the user select from a dropdown (served by another aggregate than your 'GetIdeaById', I am guessing, something like 'getApplications') The result of this selection is put into the bound variable, which is probably GetIdeaById.Current.Idea.ApplicationId. So far so good.
But that id is the only thing in your GetIdeaById.Current record that gets overwritten, even if you joined the application in it to get the IsActive of it, so GetIdeaById.List.Current.Application.Is_Active will still be the value of whatever application that is attached to your request in the database.
If you want to check if the newly selected application is active, you need to go find the active attribute of it. You already have a list of applications that serves your dropdown, so that information is in there. There are a number of ways you can get to it.
1) attach an OnChange to the dropdown, make a local variable 'selected application' and in the OnChange, fill that local with the selected application (all attributes, not just the id)
In your validation, you can look at this local variable to see of the selected application is active.
2) don't bother with OnChange and local variable, just do a ListIndexOf in your validation logic on the Applications list, finding the one where Application.Id = GetIdeaById.Current.Idea.ApplicationId, look at the record resulting from your ListIndexOf to see if it is active
Dependent on your answer on the blue question, this might still be a bit too simple of an approach, for example, maybe you have to also store the previous value, and only make the validation fail if they actually change the application for the request.
Dependent on your answer of the green question, you should only build a confirmation warning, not give validation error.
So here's a completely different approach,only show in the dropdown to the user, the applications they are allowed to choose from. A simple rule would be something like "when an application of a request is first filled in or updated, it has to be a valid application, but invalid applications on existing requests are allowed to stay"
So the dropdown should contain all the valid applications + possibly one invalid one that is already attached to this request. No more client validation logic needed, they can only choose a correct one.
For this, build the aggregate for applications with a with or without join to the current request and a filter of "Application.IsActive OR Application.Id = Current Request.ApplicationId"
All of above is only about client, you still need to repeat server validation to make sure no wrong data get updated into the database.
Dorine
Unfortunately, I cannot continue building for today. However, I think you answer will help a bunch.
In reply to your questions:
Blue: the admin will have to choose an active application instead (or none).
Green: had not thought about that, but yes, that would be a consequence.
In reply to both: the admin will also have a commentsection available in which he can post as a backup. I will try your suggestion with the aggregate however, since it seems way more sophisticated. I'll return tomorrow and let you know how it worked out.
Thank you very much. This turned out to be so helpfull:
It works in dev and it will be pushed to acceptance testing today with several other changes. Thank you!
ok,
glad to be of help.
If you are going with this approach to acc today, I'd like to just verify : did you make sure that the join condition is joining only with the current request ? otherwise, you applications that feature in multiple requests might show op multiple times in your dropdown (unless you solved it by grouping...).
That's a common test condition overlooked in a quick dev test.
Yes, the join looks at the request id, which is also an input parameter of my block. It should be fine like that.
Hi Danique.
Debug is allways the perfect option for that scenario. If you want to see what's the value of the dropdown, you can allways put the breakpoint in the start node and choose debug. Then, see the locals variable and go to the variable of that dropdown, there you can see the value of the dropdown. Also, if you click in the option "Step Into", you can analyze what your code will do and indentify the error. Here the debug course that can help you learn how to debug an app properly.
Hope I helped. If you need anything more, please send the oml file, so I can take a look and help you a little bit more.
Cheers.
Edit: I think I found the problem. If an application is not active, you put the dropdwon.valid = false. If you do that, when the code goes to the "From2.valid" it will allways be false, and of course it will not update or save the form. If one of the widgets validations is false, the entire form cannot be saved.
I don't know what you want to do for sure, if you don't want to save requests with inactive applications or if you do, but using that logic you can't.
Hi Mauro,
Thanks for your quick reply (both of them). It's meant to work like that, since I don't want the form to be able to be saved with an inactive application. But right now, I cannot edit the form once a (now) inactive application has been chosen.
The problem is that I cannot change the value once an inactive application has been saved.
I hope its more clear now. I'm currently working on an OML to clarify further.
Let me see if I understood. You saved a active application, and then when they turned into an inactive you can't edit the form?
If that's the case then I think you need to see the "enabled" property of the widgets.
Or when you choose an inactive application you can't edit the form anymore?
Send me the oml file please, so I can take a look and help you.