Hi All,
I have added some validations as below on OnInsert Trigger of one form, but when "Direct Unit Cost" is zero, it is showing ERROR message and closing form automatically.
I searched this forum for same problem, and found that if validation is there on Form this problem can happen, but for me its on Table. And I need to validate on OnInsert Trigger not on Field's OnValidate trigger.
IF Quantity <= 0 THEN
ERROR(Text037,Quantity);
IF "Direct Unit Cost" <= 0 THEN BEGIN
ERROR(Text038,"Direct Unit Cost");
END;
I don't want to close form after ERROR, is there any way to do that ?
Rakesh Patel
Navision Developer
0
Comments
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Your form closes because you've programmed the form to cause an error. When a form causes an error, the system closes it. You will not be able to change this behavior. Data validation code belongs in tables, not in forms.
RIS Plus, LLC
He can try MinValue 0.00000001 8)
But they have to enter it into the field for the message to appear
http://www.BiloBeauty.com
http://www.autismspeaks.org
As advised by some users I am not putting validation on Form but putting on OnInsert trigger of Table but its not working (I think if I put it on OnValidate event of field it will work, but in my case user may not go to this field, then it will not trigger Validation). MinValue I can't use because user may not go to this field.
Navision Developer
On insert of the table, you are talking about the entire record not just that field. what & where is the code you put on the table?
http://www.BiloBeauty.com
http://www.autismspeaks.org
We are calculating cost automatically when user enters barcode/item code and quantity. So no need for user to go on that field and enter cost manually. But sometimes they are trying to create PO without entering cost in system and its creating with zero cost. So to avoid this we want to put validation OnInsert to stop them adding record if cost is zero.
Savatage,
I have added following code on OnInsert trigger of table,
IF "Direct Unit Cost" <= 0 THEN BEGIN
ERROR(Text038,"Direct Unit Cost");
END;
and when user trying to enter record with 0 value in "Direct Unit Cost" field, it is closing for after giving error. We need to keep form open after showing error.
Navision Developer
IF "Direct Unit Cost" <= 0 THEN BEGIN
MESSAGE(Text038,"Direct Unit Cost");
END;
Or are you looking for a message and the line to clear?
http://www.BiloBeauty.com
http://www.autismspeaks.org
My code is there in OnInsert, so if i am trying to put MESSAGE, it is showing message and inserting record, i don't want to insert record if value is zero.
Navision Developer
rmpatel22 did you read this?
I will try to search solution with "Mandatory field" keyword now.
Navision Developer
It still requires user intervention, if they choose to ignore it then that's another story.
2nd, I'm assuming these are items your inserting into an order or PO or recipt. So if the cost is never supposed to be zero then why isn't that addressed when the item is being entered to begin with, instead of trying to stop it in different parts of the system?
3rd, today zero might not be acceptable, how about in the future? Perhaps a CONFIRM would be better therefore giving the choice to the user.
ex message/
"This Item has a unit cost of Zero. Is this correct?" user intervention required for y/n
http://www.BiloBeauty.com
http://www.autismspeaks.org
I will bet it started with a conversation that started something like :
"But our old system did it this way..."
I have the exact same problem than RMPATEL22: On the "OnInsert" trigger of my table, I need to validate couple fields BEFORE allowing the insertion, and if one or more of these fields are not valide, well I need to ROLLBACK, and as far as I know, the only way to rollback is by using the ERROR() fonction. I do not want my form to close right away after the error message since I need the user to correct his line before trying again. I don't get the logique of why my form is closing while the trigger is on my table.
The solutions proposed here so far in this blog don't apply to my case: Anyone has a REAL solution please, AND/OR can explain why a form is closing by itself right after an Error called on the "OnInsert" trigger of its table?
Thanx
Forget about the code, and instead explain what you are trying to do. Explain the business need.
In other words, I need the Error() fonction to behave in the OnInsert trigger of my table like it behaves everywhere else.
Thanx
-Another idea is to run a check with similar code as above. It runs thru the lines with FIND checking your fields on "Release" of your order. If errors exist then it will not allow you to release the order. What makes this easier is that the data is already entered therefore easily verified. The problem lies when the data is typed but not inserted. This is where you problem is.
http://www.BiloBeauty.com
http://www.autismspeaks.org
Put the validation in the OnValidate of the "No." field.
If you for soe reason can't accept this as a solution you need to really think about why you bought Navision. If your old system did it the way you want to do it, why did you change to Navision?
Again, an ERROR in a table trigger DOES NOT cause the form to close. If your form closes when you get an error that means that the ERROR is caused by something on the form.
I don't think you are really listening to the solutions, or you are not working your way through the entire problem, because forms simply do not close when an ERROR is caused in a table trigger. Again, an ERROR in the OnInsert trigger WILL NOT cause the form to close. If your form closes due to an ERROR, that means that the error is caused by something on the form itself.
So you want the value that is entered into the "No." field to be validated. Put the validation code for this functionality into the OnValidate trigger (not the OnInsert trigger) of the "No." field in the table object (NOT the form object), and the form will never close as a result of the error.
You need the code to be in the OnValidate trigger of the field, not the OnInsert trigger.
No there is no ROLLBACK function. ERROR will roll the transaction back automatically to the last COMMIT point, which is either where you started the manual transaction or if the code contains an explicit COMMIT statement..
RIS Plus, LLC
Run the form, and do the following:
I've tried copying the code that causes the error into the form's OnValidate and OnInsert triggers, in 4.0SP3 and in 2009SP1 and it is not even closing the form then for me. ERRORS should only close forms when they happen on the form. When ERRORs happen in tables, they should NEVER close the form.
<edit>removed FIELDGROUPS, so you can use it with other versions than NAV2009</edit>
RIS Plus, LLC
...I beg you pardon, but YES, it does!!
Thanx anyways: I'll try to with the OnValidate trigger
Perhaps there is an INSERT(TRUE) call in some logic on the form.
RIS Plus, LLC
Daveus maybe try the debugger to see where the form is closing. Though it may be impossible, since the debugger will probably trap on the first error message, not necessarily the one closing the form.
But try this form and table above, you will see that it does not close, so there must be something else in your code.
You're right, but for a reason that I can't explain, if I put an Error() right on the very first line of the OnInsert trigger of the "36-Sales Line" table, before any other line of codes, and then run the "42-Sales Order" form, then attempting to create a new sales line, the error will pop-up, then the "42-Sales Order" form will close by itself. The mentionned form and table involved had never been modified before.
But anyways, you told me to use the OnValidate trigger rather than the OnInsert trigger, and I now believe it's a better pratice, except that a line is created, then it is validated, wich means that a line is created even dough it's validation had failed! I would have liked to validate, then create the line after a successfull validation.
Sorry about the confusion: You're right that an Error() does not close a form, except for the case I just described.
Thanx for your time...
By the way, I took a standard NAV2009SP1 US database, modified the Sales Line table like you suggested, and the sales order form does not close as a result of this error. I don't think you are working with unmodified objects, but you'd have to run the debugger to make sure what happens at what time. Which version are you on?
RIS Plus, LLC
Again, thanx
There must be something else going on :-k
RIS Plus, LLC