15
Views
9
Comments
Solved
Correct approach to modifying submitted data
Application Type
Reactive
Platform Version
11.10.1 (Build 23852)

Hi All,

I have a simple form which will create a new record. The entity which will hold this new record has an attribute "Job Number" which should automatically be created as the next sequential number (last Job Number +1).

My question is where is the correct place to handle the logic?

Should I create the new Job Number and make it a non-editable input field on the form so that it exists as part of the "source"?

Should I create the new Job Number after submission?

I have tried both approaches but I'm struggling to undestand how to achieve my goal - It FEELS like I'm going about this in the wrong way and hence my stuggles.

I have followed the "Becoming a Reactive Web Developer" Guided Path but it was too superficial (IMHO) to get into these types of details.

Any help and or examples would be greatly appreciated.

Des 

Rank: #292
Solution

Hi Des,

You can create this logic inside a screen action only, use the desired aggregate in your screen and apply max function on JobNumber attribute column of aggregate. For these you need to have JobNumber(Integer) attribute in your entity.

Then inside screen action, assign form's JobNumber to the newly added aggregate(where max function is applied) JobNumber +1 and then use createEntity action.

Hope this helps!!


Rank: #94

Hello Low Coder Des,

Hope you're doing well.

If I were you, I'd implement that extra logic in a CRUD wrapper action.

Please take a look at this article.

Everytime you call your CRUD wrapper action to create a record, you can do a query to retrieve the max value for Job Number, increase 1 and the resulting value should be the value that you pass in the attribute of the new record that you're going to create.


Hope that this helps you!


Kind regards,

Rui Barradas

Rank: #1367

My suggestion would be to implement some logic when you click on the save button. I would leave the CRUD wrapper to only do the CRUD action, to keep everything clean. You can for instance implement the logic when clicking on the save button. You can retrieve the maximum job number and increase it by 1, and place this value in your record you want to save. Then you can send this record to your CRUD wrapper. 

If you want to do it even more clean, you can make a new module called the BL (business logic) module. In this module you can implement the kind of logic you are describing. For instance, you can make an action RecordCreate which holds as input the record you want to update. In this action, you retrieve the maxmimum job number, increase it by one, and assign this value to the attribute of the record you want to update. Then you call the CRUD action in this action. Now you call the RecordCreate action in your top layer when you press the save button. It will go then to the Businiss Logic module to find the correct Job Number and in the Core Services it will use the CRUD wrapper to create the record.

The big advantage of this architecture is that you have a good overview of all the seperate actions that you are doing. 

1. You can see where the save action is being called
2. You can follow the implemented logic in the Business Logic layer
3. The record is created using a standard CRUD action, for which a wrapper is made

I hope this helps you!

Kind regards,

Tyler

Rank: #292
Solution

Hi Des,

You can create this logic inside a screen action only, use the desired aggregate in your screen and apply max function on JobNumber attribute column of aggregate. For these you need to have JobNumber(Integer) attribute in your entity.

Then inside screen action, assign form's JobNumber to the newly added aggregate(where max function is applied) JobNumber +1 and then use createEntity action.

Hope this helps!!


Rank: #292

Hi Des,

Please find attached OML for the solution of your problem.

Hope it helps, Thanks a lot and Happy Coding!!

CreateNewRecord.oml