Hi,
i did search the forum regarding FieldRef as well as read the online help, but i still don't quite understand if what I want to do is possible.
I am working on an integration project. Part of the integration is data requirements on the sales order prior to interfacing them to our warehouse management system. We have a routine that we use prior to order release that checks for required fields using TESTFIELD, etc.
now, i have to potentially send 3 addresses down to the WMS. different countries require different data (is zip code required, is city, etc.). I have written repetitive code that basically says (pseudo code follows).
IF condition then begin
TESTFIELD("sell-to City");
TESTFIELD("sell-to country Code");
..
..
more logic
..
..
IF Condition2 Then begin
TESTFIELD("ship-to city")
TESTFIELD("ship-to country code");
.. more processing..
as you can imagine, i have a lot of very similar code. I check city, state, post code, and country code for sell-to address, ship-to address, and a third-party billing address. it is a lot of code doing the same thing.
i would like to create a function to handle this, but i can't get my head around how to handle this. i wondered if i could create a function that says something like
//pseudocode
If condtion 1 Then begin
TESTFIELD(fieldRef)
TESTFIELD(fieldRef2)
...
IF condition 2 then begin
TESTFIELD(fieldRef)
TESTFIELD(fieldRef3)
...
is this a valid use of fieldref?
here is an actual code snippet showing just one instance of this check. i know it isn't pretty, hence why i'm trying to make it better.
IF (recCountry."Suppress State in Rating") AND NOT (recCountry."Suppress Postal Code in Rating") THEN BEGIN
TESTFIELD("Ship-to City");
TESTFIELD("Ship-to Post Code");
TESTFIELD("Ship-to Country Code");
END;
IF NOT (recCountry."Suppress State in Rating") AND (recCountry."Suppress Postal Code in Rating") THEN BEGIN
TESTFIELD("Ship-to City");
TESTFIELD("Ship-to County");
TESTFIELD("Ship-to Country Code");
END;
IF (recCountry."Suppress State in Rating") AND (recCountry."Suppress Postal Code in Rating") THEN BEGIN
TESTFIELD("Ship-to City");
TESTFIELD("Ship-to Country Code");
END;
IF NOT (recCountry."Suppress State in Rating") AND NOT (recCountry."Suppress Postal Code in Rating") THEN BEGIN
TESTFIELD("Ship-to City");
TESTFIELD("Ship-to Post Code");
TESTFIELD("Ship-to County");
TESTFIELD("Ship-to Country Code");
END;
kind of fell into this...
Comments
First: something about FieldRef and TESTFIELD from NAV help:
TESTFIELD (FieldRef)
Use this function to see if the contents of a field match a given value. If the contents differ from the given value, the system displays an error message.
FieldRef.TESTFIELD([Value])
I would create a function which could be called with list of fields formatted as as a filter, and then do all TESTFIELDs in that function:
Having this TestFields function you can then make your tests more generic, for example:
The above tests if "Ship-to City" (field 17), "Ship-to Post Code" (field 91) and "Ship-to Country" (field 93) are not empty in tested Sales Header record if SomeCondition is true, otherwise it tests only "Ship-to City" and "Ship-to Post Code"
Just an example how to approach the subject. Is that what you're trying to do ?
Regards
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
TESTFIELD(FieldRef) and TESTFIELD (Record).
i am familiar with the latter and overlooked that there was another entry.
:oops:
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03