How to initialize variables in a form field: 

I would like the input order to start with its max value + 1, but since it belongs to a form, I cannot simply replace the variable assigned to it: QuestionForm.Record.Question.Order with any other.
To do a test, I put GetQuestion in the preparation and created the Max function for the order attribute. Then I created a local variable (TestOrder) and in the action flow of the preparation I assign this variable the following value: GetQuestions2.List.Current.OrderMax + 1
The result was very successful, as you can see in the expression on the screen: "Testing Order Max in GetQuestion at preparation:"

My difficulty is to make this change to the Order input:


In my research, I found this explanation that comes close to what I would like to do: https://success.outsystems.com/Documentation/How-to_Guides/Front-End/How_to_dynamically_set_the_values_of_inputs

So, I created it as follows, But I still haven't been successful:



Can someone let me know what I'm doing wrong?

Best Regards,

Jessica Marques


Hello there,

Your form has a source record. The value in the input, without changes, will assume the value of the variable that it is assigned to. 

As such, what you need to do is make sure that your initial value is set in the source record of the form. Subsequent changes - like onchange manipulation - shall be done to the form record - and not its source.

If this isn't clear enough, feel free to share your OML so I can exactly point out the issue and how to solve it!

Cheers! 

Hi, Jessica.

The form is been filled by the aggregate list, so the default behavior is to fill the form with the values from the database as they are.

The Order input holds the form variable and that's the problem. Create a local variable to Order, fill it with the data from aggregate +1 then change the variable of the input from the form variable to the local new one.

Armando Gomes wrote:

Hello there,

Your form has a source record. The value in the input, without changes, will assume the value of the variable that it is assigned to. 

As such, what you need to do is make sure that your initial value is set in the source record of the form. Subsequent changes - like onchange manipulation - shall be done to the form record - and not its source.

If this isn't clear enough, feel free to share your OML so I can exactly point out the issue and how to solve it!

Cheers! 

 Hello Armando, 

I've made so many attempts that now I deleted them from the module, in any case, follow the application and thank you for your help.

Best Regards, 

Jessica. 

 

Lenon Manhães wrote:

Hi, Jessica.

The form is been filled by the aggregate list, so the default behavior is to fill the form with the values from the database as they are.

The Order input holds the form variable and that's the problem. Create a local variable to Order, fill it with the data from aggregate +1 then change the variable of the input from the form variable to the local new one.

 

Hello Lenon Manhães, 

thank you for the help

I already made an attempt like this, I put an assign in the preparation with the variable, then I associated this variable with the order of the form, but I was not successful.
Where do you suggest that I should place the assign relative to this variable?

 

Best Regards, 

Jessica. 

I created the local variable 'OrderValue'. Now the input variable is this new variable (image 1);

On preparation, feed the new 'OrderValue' variable with the the value you used on the first post + 1 (image 2).

I think that way will fit. What do you think?



Lenon Manhães wrote:

I created the local variable 'OrderValue'. Now the input variable is this new variable (image 1);

On preparation, feed the new 'OrderValue' variable with the the value you used on the first post + 1 (image 2).

I think that way will fit. What do you think?



Hi Lenon,

Thank you for your help

When I create this way, the behavior is:

In this case, how do I get the current value to search for the highest value entered +1?

For example, I would like the highest order already defined on each exame to appear in this field.

I created an aggregate in preparation with this information, but I don't know how to insert it in the form of entry to change dynamically from the aggregated information.

To demonstrate what I need, I created this expression, the point here is that I cannot unite the current form with the logic of assigning dynamic order, for example, if I simply put this variable in the form it does not record any information in the entity to which the form belongs.

Is there a function that I can unite these two elements?

GetQuestionById.List.Current.Question.Order and GetQuestionsByOrder2.List.Current.OrderMax +1 ???

In short, my need is: how to dynamically change a field in a form and still be able to save what is registered in it.

Hi Jessica,

As I understood, I did below changes in QuestionDetail Preparation :

Get Max order from Questions List:-

If creating new question then initialize the order by max(order)+1:

Cheers

Solution

Hi Jessica,

If you move the value to a local variable then you need to assign the form attribute with the value of the local variable. So, on the Save you need to have an assign to do "Form.Record.Question.Order = OrderValue"


Regards,

Ricardo

Solution