Dynamics NAV & the Copy Company feature

Sorry it's been so long since the last blog, lots going on in my personal & professional life has got in the way recently but I have renewed determination to share more.

So the copy company feature Microsoft added, in I believe 2016 2013R2 (thanks Natalie Karolak who has a better memory amongst other things, than me) , is just fantastic. While you need to be aware of the performance impact if you have a large dataset, the ability to 'spin up' a copy of your live data for testing is just ace and helps the support teams no end.


But, and you knew that was coming didn't you…..

It copies at SQL Level (which makes it as quick as possible) and that means there is no business logic applied. You get an exact duplicate of the copy your copying in that new copy.

Why is that a bad thing?

Well there are a number of issues and therefore things I believe you should either do yourself or get the system to do, after that copy.


The copy can send out email's. Not a problem in itself but click post & send as part of a test transaction and how is your customer or vendor supposed to tell that the email they get is not from your 'live' company. Getting good turning up against a purchase order number that's likely to be for a completely different vendor is going to confuse your goods in completely. Who is going to pay for the 'failed delivery'?

Best to go and take out the SMTP mail server's IP address – that stops any possibility. If you need to test the email function you can always go and put them back in for the short period you need to test its working correctly.

CRM Integration

So you have the link to Dynamics CRM configured, do you want the updates from you new company flowing through? It would really mess up CRM if those test accounts and product you create get replicated wouldn't it? Better turn it off then hadn't we.


Job Queue & Scheduled Tasks

So now there is no need to start separate NAS for each company for the Job Queue to start running. It run by the middle tier service for all companies by default. That means the job's that ran in live will also run in the new copy you've just created. That at best uses resources for no benefit and at worst sends loads of data or reports out that will confuse everything.

So after your copy remember to go into the job queue and place all the job queue entries 'on hold' – you can then enable the ones you need to run when you need them.

With 2017 the Job Queue creates scheduled tasks, I'm also deleting all of those to make sure nothing executes that I'm not in control of.



Company Information

So we have a fraud risk here. Imagine if I have malicious intent and I copy your live company, create a nice large sales invoice then immediately delete that company again. If that invoice is used in a VAT claim by another company, how are the tax authorities going to look at you? Say I raise and send a nice large purchase order to a vendor that then manufactures those items specifically for this order. How will you sort that out.

The Name in the company information should always be changed to make it clear it's not the 'live' company. I like a large '*TEST*' at the start of the company name. I also clear the VAT Reg. No and the Registered Company Number field as well.

In fact I like the company name to tell me the date & time I copied this company & from where, that way I know when this data was created and how up to date the data is. That means I know if I can delete it safely which is a must if I'm not to end up with lots of 'test' companies using lots of space and resources.

No. Series

I like to change the No. Series on my copy company as well to make it doubly sure contractual business documents cannot be misunderstood. If that Purchase Order has a number of '*TEST*PO00001' it would make even your dimmest vendor ring up and check.


Don't we just love Events

So all this is lots of effort and I have to remember to do it, wouldn't it be better if the system 'just did it' for me?

Well we have a Company table and thanks to Microsoft's new development capabilities, an 'OnAfterInsert' event for that table.

So I can write a function on a custom codeunit and subscribe to that event. That means it will run my code, after its does the copy company function in the Companies page.

So on github there's a codeunit that, if you renumber (its 50000 currently), then import & compile, will make sure all of the above are done, automatically for you, every time you copy a company.

And because it's an event subscription there are no changes to standard code. You know, every time I say that phrase to myself (and its all the time these days), I just want to whoop like an American!

Have I missed anything?

I'd be very grateful if anyone could suggest anything I've missed? Feedback is most welcome.