Change "Direct Unit Cost" in a released "Purchase Order"

That is not possible!

Do you really think so?

Yes?

So did I until a few hours ago when I got an email saying that it can be changed. Maybe some unexpected side-effect of some customization with G/L accounts we made?

First thing: lets see what it does in CRONUS. Create new "Purchase Order". Create new "G/L Account" line. Release the order. Change the "Direct Unit Cost". Error……….. I should have an error!……… Where is the error?…….. Why is there no error?……… Is it a standard CRONUS?…….Yes. Definitely nothing changed…….

Let’s start debugging.

Ahah, the call to function "TestStatusOpen". This should block it.

This is the code of function "TestStatusOpen" in 2009SP1W1:

IF StatusCheckSuspended THEN

EXIT;

GetPurchHeader;

IF Type IN [Type::Item,Type::"Fixed Asset"] THEN

PurchHeader.TESTFIELD(Status,PurchHeader.Status::Open);

Do you see why it doesn’t block?

Correct: If Type is different from Item and different from "Fixed Asset" it doesn’t test the status of the header! Commenting the <IF Type IN [Type::Item,Type::"Fixed Asset"] THEN> fixes the problem.

I have to admit that I didn’t check all functionality to see if it blocks something else somewhere else.

That’s dangerous. If a purchaser creates a line with a G/L Account, and he needs to go through the Approval process. After it is approved, he can still change the "Direct Unit Cost" without having to re-approve it again.

And we have the same problem (and same solution) with Sales Order lines.

Changing native DB-cache/commit cache

Who is still on native DB? You really should think of migrating to SQL Server.

I still find some customers that are still on native DB. Some of them have problems with performance but mostly because the database is quite old and keeps growing. When they started, they maybe had 100 or 200MB of memory and in rare moments I even notice that the COMMITCACHE is no.

The best is to augment the DB Cache and set the COMMITCACHE to Yes.

How to do that? Well you can re-install the DB-service but I prefer to go into the registry and fix it there. Of course that can be very dangerous if you don’t know what you are doing (Trust me. I know what I am doing. (http://en.wikipedia.org/wiki/Sledge_Hammer! ).

First stop the service.

Start the registry editor (regedit.exe)

In the registry editor, search for the path+name of the db-file (the first file if you have more files), the path+name of server.exe, the name of the service. With all of those you will find the right entry (it is in HKEY_LOCAL_MACHINE=>SYSTEM=>Services.

You will find something like this (I didn’t copy the values column):

clip_image001

Here you can change the settings.

CACHE: the size in MB of the cache.

COMMITCACHE is 0 (=false) or (1=true)

Of course you can also change the other value, but I never tried that.

After you changed the value, just restart the DB service. It will have the new values (of course they must be legal values).

NAV Techdays 2012

Well, first we didn’t plan a NAV Techdays 2012. We planned it for 2013. But here it is: NAV Techdays 2012.

I have good news and bad news about the sessions!

I’ll start with the good news: FULL (almost) of Dynamics NAV 7 …. erm… Dynamics NAV 2013 sessions!

The bad: guaranteed headache to choose the sessions you want to follow (at least if you are not able to be in 2 places at the same time…).

Here is a list of NAV 2013 sessions (copied from http://www.navtechdays.com/2012/):

  • NAV on Azure (NAV deployment, Click once, administration, creating solutions, upgrade, new authentication model)
    Christian Heide, Kamil Koclega, Jens Møller-Pedersen
  • What’s new for dataaccess: ODATA, Query, Security filtering etc.
    Claus Jakobsen, Bardur Knudsen
  • Web client, NAV portal framework and application
    Kim Carrock Kobberø, Lukasz Zoglowek, Oleg Romashkov
  • What’s new in Reporting
    Torben Meyhoff, Gaurav Roy
  • New server capabilities: RTC NAS & Job queue, NAV Server admin tools & scripts, unicode, 64-bit
    Uffe Kjall, Bardur Knudsen
  • Scrum introduction (and how it’s used by the Microsoft Dynamics NAV team)
    Mogens Nielsen, Jens Møller-Pedersen
  • What is new in RTC (Filter variables,Grouping and Grid layout)
    Thomas Vestergaard, Mogens Nielsen
  • C/AL coding for performance (SETAUTOCALCFIELDS, Query, Dimensions refactoring, Locking improvements)
    Jesper Falkebo, Bardur Knudsen, Lars Hammer
  • Working efficiently with C/AL (New debugger, Page testability, How to write good C/AL Unit Tests)
    Soumya Dutta, Elly Nkya

And this link can be useful: http://www.navtechdays.com/2012/registration.asp

Don’t wait too long to register! Registrations are limited.

Does this code work or not?

It does compile without errors. But does it also run without errors?

datshipmentdate := 01072012D;

intDateDec := 9999;

intDateDec := (CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) / 86400000;

MESSAGE(’%1′,intDateDec);

I’ll give the SQL answer (even if SQL has nothing to do with it): it depends.

It works on 4.0SP3 Build 25638,5.0SP1 Build 26084.

It gives an error on 5.0SP1 Build 30488,NAV2009 build 27808,NAV2009SP1 build 29227,NAV2009R2 32228

The error is:

Overflow under type conversion of Decimal to Integer.

Value: 11,869.9583333333333

Other builds I didn’t try, but it is clear that between builds 26084 and 30488 something has changed internally in C/AL.

In the older versions, the result is implicitly converted to an integer but not anymore in the newer versions.

These are 2 versions that work:

datshipmentdate := 01072012D;

intDateDec := 9999;

intDateDec := ROUND((CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) / 86400000,1);

MESSAGE(’%1′,intDateDec);

or also:

datshipmentdate := 01072012D;

intDateDec := 9999;

intDateDec := (CREATEDATETIME(”datShipmentdate”, 0T) - CREATEDATETIME(010180D, 0T)) DIV 86400000;

MESSAGE(’%1′,intDateDec);

Blogging

I have been using OneNote to write a blog post. After that, I copied the text directly to the blog. Not exactly the easiest way but it worked.

Now, I have discovered a new tool that works a lot better. It is from Microsoft and it is free (yes, they have free software too!): Windows Live Writer (http://explore.live.com/windows-live-essentials-other-programs?T1=t5).

Too few VLF’s in the transaction log

Someone remembers I wrote about too many VLF in the transactionlog (http://mibuso.com/blogs/kriki/2008/12/23/some-tips-tricks-for-the-transaction-log/ ) and how to fix it?

Well, I just found a blogpost, stating that also the contrary can create performance problems.

Basically : if your VLF is too large, it takes too long before SQL Server can clear it and it takes too long to clear it.

Read more details here : (http://www.sqlskills.com/BLOGS/KIMBERLY/post/Transaction-Log-VLFs-too-many-or-too-few.aspx).

NAV Security using Windows Groups

Some time ago, one of my colleagues had a problem with security in NAV. She created security for some users so they should only be able to see some companies, but not others.

After setting it up and letting the users log off and on again, they still saw all the companies. Why was that?

When I took a look at the Windows logins , I found a Windows Login that looked more like a Windows Group (it was named something like domain\navusers) than a normal windows user login. Checking the roles attached to that login, I found that it was SUPER user in all companies.

Probably the user was also part of that Windows group. How can you check that (apart from asking the domain admin)?

There is table 2000000056:”User SID”. You need to create a form/page/report on that table and run it using the users session. It shows all the windows logins and windows groups of the current(!) user.

And in the list was the group domain\navusers. So the current user was SUPER in ALL companies.

Removing the SUPER from that user and after letting the user logoff and on, the user saw only the companies he should see.

Another thing about security I want to add is this: the security each user has is the union of all security-settings of all the groups the user belongs to.

Migrate from Native to SQL Server : dates before 1753/01/01

Now that the native database is destined to disappear, it is more than ever time to migrate your database to SQL Server.

 

Most migrations have some problems with dates.

If you have dates in your system before 1753/01/01 [rambling]Of all date-representations, I prefer the year/month/day because it is the most logical. After all, we write hundred and twenty three as 123 and not  321 (or even worse 213)[/rambling], you have a problem because SQL server does not accept dates before that date in a datetime variable (the variable type used to store C/AL DATE,TIME,DATETIME datatypes).

 

How to fix it? Of course there is the migrate.fob on the installation DVD to fix it, but if you have a BIG database, it will take a lot of time. And generally, you don’t have much time to do the live-migration. And if you do, it generally means you do it during the weekend and most of the time you would like to be at home with your family during the weekend (at least I do).

 

And if you have some problem dates, it generally takes time to fix them. In some date-fields you can’t just throw in any date you like (even less the one proposed by the migrate.fob).

Last time I had the problem, I had the accountants turning white and almost having a heart attack when I mentioned that I found some “Posting Date” fields in T17:”G/L Entry” with dates of about 2000 years ago.

Fixing these dates costs time (in this case I was lucky because it was the beta-migration, but still, it had to be fixed in the production database. And after fixing them, it is still possible users put in other bad dates.

 

So, the best way is to avoid that user can put in bad dates. But how? Actually, it is quite easy.

 

In codeunit 1, there is a function “MakeDateText(VAR DateText : Text[250]) : Integer”. This function is called whenever the user fills in a date-field. So you can block when the user puts in a bad date.

 

This is the code-change you need:

 

MakeDateText(VAR DateText : Text[250]) : Integer

Position := 1;

Length := STRLEN(DateText);

ReadCharacter(’ ‘,DateText,Position,Length);

IF NOT FindText(PartOfText,DateText,Position,Length) THEN

 

//START

{OLD CODE

  EXIT(0);

}

  BEGIN

    Date1 := DMY2DATE(1,1,1990);

    EVALUATE(Date,DateText);

    IF Date < Date1 THEN

      ERROR(’Date (%1) must come after %2′,Date,Date1);

    EXIT(0);

  END;

//STOP

 

It does not stop programs to put in bad dates, but at least it stops users from doing so.

 

BTW: some things to improve in my code: you might put the minimum date as some setup and instead of using a literal string in the ERROR, you should use a text constant.

 

These are the steps to make your migration (more) painless:

-Put this code in place as soon as possible (even if you are not planning a migration to SQL Server soon, it will help saving the hearts of your accountants).

-Let the users logout  so when they log in again, the code is active.

-Run the migrate.fob to fix the wrong dates as soon as possible BEFORE the migration (preferable before both beta- and live-migration). You might run the migrate.fob each week or 2 before the migration just to be sure.

-When you get to the live-migration, you don’t need to run the migrate.fob anymore and save some time.

NAV TECHDAYS 2012

We have a new NAV techdays this year!

Thursday 27 & Friday 28 September 2012
Metropolis Business & Communication Center, Antwerp (Belgium) (the same as last year) (I wonder if also the T-shirts will be the same colo(u)r as last year :-)

If you missed it last year, this year you can make up for it!

NAV Techdays, the day after (well, less or more…)

It took some time before I wrote the after-event blog but I have been busy with work these weeks. And to be honest I had also to think a lot about what I wanted to write and how. This post is just the beginning.

First and for all, I have to congratulate Luc for the amazing job he did organizing this all on his own (I had very little participation. I only helped a little.)

He had organized everything so well that we both could follow the sessions we wanted without problems.

Some comments on some sessions I followed.

First about the closing keynote: The Luc factor … euh … The Luck Factor. I didn’t follow all sessions, but I do think this was the funniest session. After some deep technical sessions, this one was perfect for closing these 2 days of high-concentration sessions.

The session that I looked most forward to follow, was Vjeko’s “Interop :The Beauty meets the Beast”. A few weeks before I started studying C# to have a better grasp to use it with NAV .NET Interop.

He did a very good job explaining everything, but I think that for people who never looked at C# will have had a hard time to follow anyway. There were a lot of thinks I easily understood because I already started studying C#. Without it, I think it would have been hard to understand all.

Very well explained and I definitely learned something (and also got some ideas to implement and I already started doing some stand-alone in C# and maybe I will blog about them later).

Another session that I thought would be interesting, but it turned out to be very interesting and I hope it will become an initiative that the whole NAV-world will follow and take part in. The session is “Partner-ready Software: how to build software for others to maintain”.

It is about how we design NAV-software and how we can improve it.

I give you the advice to check out their slights, the film of their session and also their website : http://www.partner-ready-software.com/index.html

Their initiative urges me to write a series of blogs that will be closely related to partner ready software.

Don’t forget to check out also the following blogs (if you didn’t already do it):

http://mibuso.com/blogs/kine/2011/10/04/navtechdays-memories/

http://mibuso.com/blogs/waldo/2011/10/03/navtechdays-as-a-speakerexhibitor/

http://www.kauffmann.nl/blog/index.php/2011/10/01/nav-techdays-2011

http://community.dynamics.com/product/nav/navnontechnical/b/navigateintosuccess/archive/2011/09/30/the-beauty-and-the-beast-nav-and-net.aspx

Create a new blog and join in the fun!