Autopopulate input text

Hello All,

I have two blocks, in the parent block there is a add button, which on clicking will take the user to the child block, where the user can fill the data.

There is one input field, where the the data will get autopopulate from the database on clicking of the Add button.

For e.g. there is a input field called Registration Number. On clicking of the add button, the registration number should get get autopopulated with the number i.e. last saved registration number + 1. I.e. if the last saved registration number is 0123, then on clicking of the Add button, the registration number input box should get autopopulated with 0124(0123+1).

This is done in reactive. I tried using the OnReady action, but it is not working. So, it will be really helpful if anyone can help me in this regard. 

Thank you


Hi @Runisha Rajkhowa,

I believe you want a button to get the next registration number fetching it from a database (this as Block 1) and its input field to be shown only after knowing that value (as Block 2). 

First of all, when using Blocks we need to keep in mind they won't refresh their parents unless using Events (from child) that are caught by Handlers / Actions (from parent) where you can use Input Parameters (the word Input looses a bit of sense, but that's the way it is). Next thing to know is the OnParametersChange Event a Weblock triggers each time one of its Input Parameter changes (or has any assign outside the weblock, even if the value remains the same). 


I tried to build a quick use of your needs, but this solutions assumes the Registration Number can not be changed by the user (only shows the value in the screen). If its also supposed to allow the user to change this number, a new Event in Block 2 (and a new Handler in the screen with the save action) would be required. But let's see an example...


We have this Students' table:

   

We have a Detail page (edit/create) with 1 Aggregate, 2 Blocks and 1 Client Action as Handler.


Block 1's event is mandatory, so you must have an Handler in this page: 

The Handler (a Client Action) simply saves the number we'd get from Block 1's Event (passed as an input parameter) to the Aggregate's Current (since we can use the Aggregate as a variable). The logic of adding one was already done in Block 1's event:  

Block 1 has 1 Aggregate (to fetch only on demand after clicking the button).

We can get the Max value (Calculated attribute) and I used an After Fetch event to be sure we do have data retrived from the DB before we calculate the value + 1. We now just need to pass that value by triggering  an Event (through its input parameters):


(An opcional approach could be using an aggregate returning only 1 record and ordering desc by the Registration Number.)


Block 2 has a Number input that shows the mandatory input received (a.k.a. our new registration number) and can have some logic to just show this container after its input parameter changes (and if it's different from 0, the integer's default  value). 

We can run a Client Action every time an input parameter of the block has any assign outside the block (even if the value remains the same). To do that, we need to add it as the handler of the On Parameters Changed block's event:


So our page for New Student appears this way, only showing the next number after clicking the button:


The Registration Number input can be Enabled but, as previously mentioned, changing it by the user will not update its value to the parent's block, so saving it (in the action inside the page) will still use the previously fetched value from Block 1's button. Why? Because we're using blocks and parents (blocks or pages) can't access child's block values. So it might be better to have Enabled as False or, if we did want to allow changes by the user, do proper event / handler with input parameters as we did for Block 1.

Just to end, some advice in keeping database integrity. Besides showing the Registration Number on the screen, please keep in mind if this screen will be used by multiple users at the same time.  If that's the case, the Server Action just before creating/updating the record should get once again the Registration Number since during the time one user was fetching the number and/or clicking in the save action (client side), another user could just upserted a record with the same Registration Number.


Please let me know if this helped in any way!  Thanks,

Fábio


Thank you so much @Fábio Godinho. It really helped me solve the problem.



Hi Runisha,

you can calculate the Registration Number in the parent block and send as parameter to the child block.

Regards

Hello Jose, thank you for your time and suggestion.

Hi @Runisha Rajkhowa ,

I think major part of your work was done, Please share your OML so that by checking the code, will try to help with some changes what you need to do.

Before that do the following steps if you haven't done.

1. Add one event and set it as mandatory

2. Add input parameter and pass the value of incremented through that input parameter.

I hope this helps and you'll found the solution.

- Palle Vijay Bhaskar Reddy

Hello @Vijay Bhaskar Reddy Palle, thank you so much for your time and suggestion.

Hi @Runisha Rajkhowa,

I believe you want a button to get the next registration number fetching it from a database (this as Block 1) and its input field to be shown only after knowing that value (as Block 2). 

First of all, when using Blocks we need to keep in mind they won't refresh their parents unless using Events (from child) that are caught by Handlers / Actions (from parent) where you can use Input Parameters (the word Input looses a bit of sense, but that's the way it is). Next thing to know is the OnParametersChange Event a Weblock triggers each time one of its Input Parameter changes (or has any assign outside the weblock, even if the value remains the same). 


I tried to build a quick use of your needs, but this solutions assumes the Registration Number can not be changed by the user (only shows the value in the screen). If its also supposed to allow the user to change this number, a new Event in Block 2 (and a new Handler in the screen with the save action) would be required. But let's see an example...


We have this Students' table:

   

We have a Detail page (edit/create) with 1 Aggregate, 2 Blocks and 1 Client Action as Handler.


Block 1's event is mandatory, so you must have an Handler in this page: 

The Handler (a Client Action) simply saves the number we'd get from Block 1's Event (passed as an input parameter) to the Aggregate's Current (since we can use the Aggregate as a variable). The logic of adding one was already done in Block 1's event:  

Block 1 has 1 Aggregate (to fetch only on demand after clicking the button).

We can get the Max value (Calculated attribute) and I used an After Fetch event to be sure we do have data retrived from the DB before we calculate the value + 1. We now just need to pass that value by triggering  an Event (through its input parameters):


(An opcional approach could be using an aggregate returning only 1 record and ordering desc by the Registration Number.)


Block 2 has a Number input that shows the mandatory input received (a.k.a. our new registration number) and can have some logic to just show this container after its input parameter changes (and if it's different from 0, the integer's default  value). 

We can run a Client Action every time an input parameter of the block has any assign outside the block (even if the value remains the same). To do that, we need to add it as the handler of the On Parameters Changed block's event:


So our page for New Student appears this way, only showing the next number after clicking the button:


The Registration Number input can be Enabled but, as previously mentioned, changing it by the user will not update its value to the parent's block, so saving it (in the action inside the page) will still use the previously fetched value from Block 1's button. Why? Because we're using blocks and parents (blocks or pages) can't access child's block values. So it might be better to have Enabled as False or, if we did want to allow changes by the user, do proper event / handler with input parameters as we did for Block 1.

Just to end, some advice in keeping database integrity. Besides showing the Registration Number on the screen, please keep in mind if this screen will be used by multiple users at the same time.  If that's the case, the Server Action just before creating/updating the record should get once again the Registration Number since during the time one user was fetching the number and/or clicking in the save action (client side), another user could just upserted a record with the same Registration Number.


Please let me know if this helped in any way!  Thanks,

Fábio


Thank you so much @Fábio Godinho. It really helped me solve the problem.



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