Changing field value through code

Hello all,

I’m trying to include a field on a report that will change based on the dimension used. I wrote the following which works fine for one department but I can’t seem to make it work for all departments that begin with “FL”. I’m not new to NAV but extremely new to writing C/AL, so this is hopefully something simple that I’m looking missing.

IF “Shortcut Dimension 1 Code” = ‘FL-CABS’ THEN
CompName := ‘Company A’
ELSE
CompName := ‘Company B’;

Hopefully I’m making sense here. Any help would be greatly appreciated.

Your code should look something like:

SETFILTER(“Shortcut Dimension 1 Code”, ‘FL*’);

IF FINDFIRST DO
REPEAT
IF “Shortcut Dimension 1 Code” = ‘FL-CABS’ THEN //…or whatever
CompName := ‘Company A’
ELSE
CompName := ‘Company B’;
UNTIL NEXT = 0;

Thanks for the reply anfinnur,

I tried the code you provided but it didn’t yield the desired results. Probably because I didn’t explain it very well…sorry. If we print a purchase order and it has a department code that begins with FL- (FL-CABS, FL-APPL, FL-ELEC etc.) then the field should display Company A. If it has any other department code (LA-CABS, TX-APPL, AR-FLOOR) then the field should display Company B. Make sense?

This, or soemthing simialr, should provide the result you need.

IF STRPOS(DimensionCode, ‘FL’) = 1 THEN
DisplayField := ‘Company A’;
IF STRPOS(DimensionCode, ‘LA’) = 1 THEN
DisplayField := ‘Company B’;

Still doesn’t seem to get it. What should the datatypes for the var’s be?

It would seem as though I was making it harder on myself than it actually had to be. I was focusing too much on using the dimension as the deciding factor for the company name. Instead I used a field on the header that designates the state which works quite nice. Thanks for the input, it’s nice to know that help is out there, even for the rookies. Not really sure what I would do without this site.

IF “Ship-to County” <> ‘FL’
THEN
CompName := ‘Company A’
ELSE
CompName := ‘Company B’;

Firstly welcome to C/SIDE

But really you are going about this completely the wrong way, and to be honest I am not to happy with the advise you are being given. You should NEVER hard code soltions like this. I guarantee that next week, next month or next you it will come back and bite you and bite you bad.

By using any code that contains 'FL*" or ‘FL-CABS’ you are creating a disaster. The correct solution is to use the Database, add a field somewhere to craete business logic. For example you could add a field “Company Dimension 1” to the Company Table, and check if it matches FL-CABS.

Hello Everybody,

as we are not speaking about SQL-optimisation here, please code “the native way”. Other users, especially newbies, want to try the code and it will not work on the native database. Which will raise new questions and the user is frustrated. So, please, I am speaking here to the professionals using NAV so long, code “the native way”. Thank you.

Walter

Actually Walter, I think there is a double wrong here.

Firstly I disagree with your statement. I believe that we shoudl all be using the new functions whether Native or SQL. But more importantly it should not be FINDFIRST, it should be FINDSET. In Native of course, both these are anyway just ranslated to FIND(‘-’) anyway, so its really only SQL where this was wrong.

By the way I virtually NEVER us FIND(‘-’) anymore I now always use the 4.00 functions unless a client is on Pre 4.00

David, please read my statement, then your statement and then tell me where you disagree. You are saying the same like I do. BTW, my native 4.00 client does neither hav FINDFIRST nor FINDSET nor nor nor…

Ok now I am completely lost. Are you saying that you can not use FINDFIRST and FINDSET in 4.00? Are you sure you dont mean 3.70? My disagreement is that I am saying we SHOULD use FINDFIRST and FINDSET in both Natvie and SQL implementations.

FINDFIRST IS the new native way, has been ever since 4.0 SP1 I believe. Check out the latest version of NAV and you’ll find tons of new codewords in standard code. I understand your concern, and agree that we should be aware of what is out there, but I think you are mixing up “native vs SQL” and “old vs new versions”.

Yes, indeed 4.00 does not have FINDFIRST, FINDLAST, FINDSET etc. pp.

But Daniel is right here. I am mixing up “old” and “new”. The new codewords are intruduced in 4.0 SP1 for both navite and SQL.

However, I just wanted to point out that, still a lot of installations out there are running on 3.x (and 4.0 no SP [;)] ) so others might be confused about FINDSET etc. But this actually is now completely off topic.

Ah Ok that explains it. Sorry, I have never used 4.00, I took one look at it and said "Yep lets wait for the service pack, which I then said again when SP1 came out [;)]

Anyway, based on that logic, we should say that we shoudl not allow posts about XML, since that is also “New” [;)]

PS: Why don’t you upgrade executables to SP3 its a much better product.

But getting back on topic, the issue here is that a newbie is asking about Hardcoding, and getting feedback that sort of indicates that hardcoding is acceptible and to me Hard Coding is NEVER an option.