I've created a CommandButton (New) and I'd like to set the button to create 3 records in the form with different default values.
I'm using the InitValue() against the correct datasource (ROUTE)
currently my code looks like this - however it only returns one record!
public void initValue() { super(); //Set default values for the 1st record Route.OprId = 'Kitting'; Route.OprNum = 5; Route.insert(); //Set default values for the 2nd record Route.OprId = 'ASSY005'; Route.OprNum = 10; Route.insert(); //Set default values for the 3rd record Route.OprId = 'ASSY010'; Route.OprNum = 15; Route.insert(); }
I would also like this update to only happen when I press the commandbutton in question (I will need to create another command button that should operate as per AX 2012 standard functionality)
Could anyone please advise?
Thank you
Thanks Martin,
I'll start to do some research on how to do the above.
Thank you for your input
In that case, you'd quickly see the flaw in your code, because you're trying to add those three records every time when a new record is created, i.e. every time when an engineer tries to add a new operation. Clearly running your code on record creation is a mistake. Use a regular button, override its clicked() button (if it's a standard form, use an event handler or a control extension) and call a method with your code from there. Don't use any command button.
By the way, think about what will happen if the button is pressed for second time. Maybe you want to check whether the records exists before creating them.
Hi Martin,
Thanks for the response.
The scenario I have is that users need to create a new route in AX, but they also need to add/delete operations on that route. So for instance an engineer would create a new blank route, for this the first 3 records will always be the same with default values. However they still need the option to add more operations to that route so they will need to keep the functionality of creating new operations. I just want to save them some time by having a button on the form that if they press, it will populate the first 3 rows and save them time.
Does that make sense?
I'm fairly new to the development side of things so any pointers on what methods to use or overwrite would be very much appreciated.
Thank you
Your current code is definitely wrong. initValue() method is called when a new record is being initalized and its purpose is initializing default values of fields. The record may later saved by user (if its validated successfully) and the work is done by write() method. Your code doesn't do what initValue() is for and therefore it doesn't belong there. If users can create new records, these three records would try to be created every time.
Another problem is in the you create records, but you don't load them to the form.
I don't thing that you should be using any command button at all. You should disable creation of new records (AllowCreate=No), use a regular button (not a command button) and call your code from there. After inserting records, call research() method of the data source.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156