Problem Setting Values on New Record in Subform

bob_up
Member Posts: 155
I have a subform which contains a list of payments and dates. When the user proceeds to the next blank line on my subform, I populate the payment amount with the amount from the preceeding line and the date with the date from the previous line plus 1 month.
I have added the following code to the OnNewRecord trigger :
IF BelowxRec THEN
BEGIN
IF (xRec."Posting Date" <> 0D) AND (xRec.Amount <> 0)
AND (TotalLineAmount < PrepaymentHeader."Prepayment Amount") THEN
BEGIN
RemainingAmount := PrepaymentHeader."Prepayment Amount" - TotalLineAmount;
"Posting Date" := CALCDATE('1M',xRec."Posting Date");
IF xRec.Amount <= RemainingAmount THEN
Amount := xRec.Amount
ELSE
Amount := RemainingAmount
END;
END;
TotalLineAmount is a running total of the lines on the subform. This gets updated by the OnInsertRecord, OnModifyRecord and OnDeleteRecord triggers. PrepaymentHeader."Prepayment Amount" is the maximum allowable value for TotalLineAmount, from the mainform Sourcetable.
The code works, up to a point. When the user moves down to a blank line, the date and amount fields are populated correctly. But then the user cant proceed to create any more lines. The new line never gets inserted. If the user moves back up to the previous line, the newline disappears.
Autosplitkey is TRUE.
MultipleNewLines and DelayedInsert are both FALSE and changing their values doesnt make any difference ...
I have added the following code to the OnNewRecord trigger :
IF BelowxRec THEN
BEGIN
IF (xRec."Posting Date" <> 0D) AND (xRec.Amount <> 0)
AND (TotalLineAmount < PrepaymentHeader."Prepayment Amount") THEN
BEGIN
RemainingAmount := PrepaymentHeader."Prepayment Amount" - TotalLineAmount;
"Posting Date" := CALCDATE('1M',xRec."Posting Date");
IF xRec.Amount <= RemainingAmount THEN
Amount := xRec.Amount
ELSE
Amount := RemainingAmount
END;
END;
TotalLineAmount is a running total of the lines on the subform. This gets updated by the OnInsertRecord, OnModifyRecord and OnDeleteRecord triggers. PrepaymentHeader."Prepayment Amount" is the maximum allowable value for TotalLineAmount, from the mainform Sourcetable.
The code works, up to a point. When the user moves down to a blank line, the date and amount fields are populated correctly. But then the user cant proceed to create any more lines. The new line never gets inserted. If the user moves back up to the previous line, the newline disappears.
Autosplitkey is TRUE.
MultipleNewLines and DelayedInsert are both FALSE and changing their values doesnt make any difference ...
0
Comments
-
The user needs to change something for the record to be saved.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Can I 'trick' the form into updating the table ? Can I make it think the data has been changed ?0
-
It appears that all I need to do is to tab from one field to the other on the screen and the INSERT is triggered. Is there no way to trigger the INSERT in code ?0
-
Do you want to use a Confim message like
"Would you like to insert a new line" Yes/No or would that be too annoying?0 -
I'm not sure I understand your suggestion. The spec. for this form says that, if the user moves to a new line, that date and amount fields on the new line will default to those from the previous line. If these defaults are ok, the user can move immediately to the next blank line and the processing will be repeated, up to a total amount which is defined on the mainform. Unfortunately, it seems that the form wont insert the new record if there has been no keyboard or mouse activity. Frutratingly, just moving from one field to another is enough to trigger the insert.
Is there some way that a confirm message could help ? I tried adding an INSERT statement to the OnNewRecord trigger, but that trigger is not within a 'write transaction' ... ie, you cant update the database from there.
Thanks for your suggestion though.0 -
i was thinking adding a confirm and on confirm of yes it would
currform update or table insert command would run
IF CONFIRM('Would You Like To Add A New Line?',TRUE)
THEN blag blah blah
sombody is going to have to click something somewhere - even if it's just some phoney boolean field on the line.0 -
Thanks for replying, Harry. I'm sorry but would you please clarify this further. Is the confirm prompt just to generate a click or a keypress or are you saying we would also need to do some processing after the confirm, such as an insert ? If we need to do more processing I think we would arrive in another dead end, because you cant perform an insert from the OnNewRecord trigger. I tried variations on Currform.UPDATE from that trigger too, to no avail
Unless you can think of a different trigger from which to perform the insert.
We are fighting a battle to win over a key individual at a new client. They have just migrated from another system and are complaining that certain functions within Dynamics are much more 'long-winded'. So I am trying to give them comparable functionality to their old system.
As you suspected, I dont think the prompt on each new line is going to be impress them.
That will teach me !! I assumed "Anything that old system can do, Dynamics can do better ...".0 -
Try using windows script hosting to trigger a keyboard action such as tab.
1. create automation variable WshShell using automation server Windows Script Host Object Model, WshShell class
2. Code...
OnNewRecord trigger:
CLEAR(WshShell);
CREATE(WshShell);
WshShell.SendKeys('{HOME}');
WshShell.SendKeys('{TAB}');Regards,
Bob
NY0 -
Bob
Problem solved =D> That worked a treat.
I know with some automation objects there can be a problem with compiling objects on site. Is Windows Script Hosting pretty universal ?
Thank you
Bob0 -
Bob,
To the best of my knowledge, Windows script hosting is pretty universal and is included with any Windows os.
yw
BobRegards,
Bob
NY0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions