So, my ISUser field "Location" has a TableRelation to the table "Location".
Basically, what I would like to do is this:
IF NOT VALIDATE(ISuser.Location, 'asdf') THEN
EXIT('Invalid location');
The problem is VALIDATE does not have a return value, and instead causes a runtime error (which is impossible to catch in Navision from what I gather).
I guess I could go:
IF NOT location.GET('asdf') THEN
EXIT ('Invalid location')
ELSE
ISuser.Location := 'asdf';
But this solution requires a variable for all fields I want to check for valid values, and there are quite alot. It seems to me like there might be an easier way. Any suggestions?
Answers
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
To my knowledge, Navision only checks the TableRelation property when you call the VALIDATE function.
You can, for example, insert the following:
and end up with an invalid value in the location field - even though this field has a TableRelation property (With ValidateTableRelation set to Yes).
So my question of how to validate a value for a field without causing a runtime error upon an invalid entry remains. Using GET first works, but only when the field is a key.
recLocation.RESET;
recLocation.SETCURRENTKEY("the best key you can find");
recLocation.SETRANGE(Code,cust.Location);
// optional other filters
IF recLocation.FIND('-') THEN
MESSAGE('
ELSE
MESSAGE('
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
RIS Plus, LLC
The problem (and the reason I am going on about this) is that I have many fields I want to validate, and I want a specific error message for each of them. This means I would need one codeunit per field to validate, and that doesn't seem like a good option to me.
My apologies for not being more specific about the number of fields and the specific error messages.
Maybe I could go with a middle-way solution and use manual checks (using GET or whatever) with simple key tables, and write codeunits for the fields with more complex keys. I'll see how it works out.
Anyway, thanks for your input.
1) Call a codeunit (as described) with "if codeunitxy.run..
2) Use this codeunit for all validates
3) In the codeunit use a global variable, which you use to set a specific text (e.g. "Error on validating field xy with value zz")
4) Set this global variable, then use the validate
5) in case of any error the codeunit is terminated, its return value is false
6) use a function (eg getLastErrorText) on the codeunit to yield the LastErrorText
7) Pray for a comprehensive error handling in future version
Hope this may help
Thomas
However, my application is a web application where I have a XML document with field information I need to validate without causing a runtime error. Instead I need to use EXIT('Specific error message') when an error occurs.
And since I can't pass the XML document (Automation) to a Run() function without storing the data, this option won't be optimal.
What I would do is this: on 1 of the fields I would put a filter that is the number of the field to be checked. In the codeunit you can get this filter and you have the record with all the values and you know which field to check.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
I suppose I could store my variable in some table and pass a Rec of that table to the codeunit, but that seems like a really messy way of doing it.
Then you run your codeunit and that codeunit can get the automation-variable stored in a global of the singleinstance-codeunit.
Didn't try it out though.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
The basic idea is you make your automation a global variable. Then you have getter and setter access functions.
In fact, I believe they do exactly what you want to do -- passing a reference of the XMLDom.
You do not need to use single instance codeunits -- in fact, you probably shouldn't unless you have some good reason.
Now I am annoyed I didn't think of this before!
Thanks to everyone for your help, really helps me in the final stages of this project.
Setting this baby to SOLVED \:D/
RIS Plus, LLC
IF NOT CODEUNIT.RUN(CODEUNIT::"Sal.&Purch. Invoices",recGenJournalLine) THEN
MESSAGE('Error during Inserting data');
i have an error that tells me that i can call a CU only if the return value is not used, i m bored because i write the CU only for using return value.
So what can i do, is there something missing to make it run ?? :-k
Or if that doesn't work try it with a CU variable instead of CODEUNIT.RUN.
some C/AL functions can't be used in writng transaction because (one table ore more are locked) like codeunit.run() is allowed only if the return value is not used (ok := codenit.run() is not allowed. in the table 81 properties i can't set permissions for CUs only for Tables
[-X [-X [-X [-X [-X [-X [-X [-X [-X
NEVER use the ID of an object, but ALWAYS the option of the object like in CODEUNIT::"The Codeunit"!
If you do this, you can make upgrading or searching where an object is used a lot more difficult.
PS. don't take it personal, it is an error a lot of people make.
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!
Sorry for the confusion! :oops:
Thomas
Your problem, however, seems to be that you are running your codeunit in the middle of a transaction. You need to make the call outside a transaction - either by placement in code, or by using COMMIT to end the transaction (not recommended).