OBJECT Report 50044 Combine Customers { OBJECT-PROPERTIES { Date=05/10/06; Time=[ 4:05:48 PM]; Modified=Yes; Version List=; } PROPERTIES { ProcessingOnly=Yes; OnPreReport=BEGIN IF NOT CONFIRM(STRSUBSTNO(TecText,CustomerNo1,CustomerNo2)) THEN ERROR(''); Customer.GET(CustomerNo2); Customer.DELETE; CommentLine.SETRANGE("Table Name",CommentLine."Table Name"::Customer); CommentLine.SETRANGE("No.",CustomerNo1); IF CommentLine.FIND('-') THEN REPEAT CommentLine2.SETRANGE("Table Name",CommentLine."Table Name"::Customer); CommentLine2.SETRANGE("No.",CustomerNo2); IF CommentLine2.FIND('+') THEN; CommentLine3 := CommentLine; CommentLine3."No." := CustomerNo2; CommentLine3."Line No." := CommentLine2."Line No." + 10000; CommentLine3.INSERT; CommentLine.DELETE; UNTIL CommentLine.NEXT = 0; CommentLine2.SETRANGE("Table Name",CommentLine."Table Name"::Customer); CommentLine2.SETRANGE("No.",CustomerNo2); IF CommentLine2.FIND('+') THEN; CommentLine3.INIT; CommentLine3.Code := 'MERGE'; CommentLine3."Table Name" := CommentLine3."Table Name"::Customer; CommentLine3."No." := CustomerNo2; CommentLine3.Date := TODAY; CommentLine3.Comment := 'Customer ' +CustomerNo1+ ' was merged'; CommentLine3."Line No." := CommentLine2."Line No." + 10000; CommentLine3.INSERT; DefaultDim1.SETRANGE("Table ID",DATABASE::Customer); DefaultDim1.SETRANGE("No.",CustomerNo1); DefaultDim1.DELETEALL; Customer.GET(CustomerNo1); Customer2 := Customer; Customer.RENAME(CustomerNo2); Customer2.INSERT; Customer2.DELETE(TRUE); END; } DATAITEMS { } REQUESTFORM { PROPERTIES { Width=8910; Height=3960; } CONTROLS { { 1000000000;TextBox;3960 ;550 ;4620 ;440 ;SourceExpr=CustomerNo1; TableRelation=Customer } { 1000000001;Label ;550 ;550 ;2860 ;440 ;ParentControl=1000000000; CaptionML=ENU=Delete Customer } { 1000000002;TextBox;3960 ;1210 ;4620 ;440 ;SourceExpr=CustomerNo2; TableRelation=Customer } { 1000000003;Label ;550 ;1210 ;2970 ;440 ;ParentControl=1000000002; CaptionML=ENU=Merge into Customer } } } CODE { VAR CustomerNo1@1000000000 : Code[20]; CustomerNo2@1000000001 : Code[20]; Customer@1000000002 : Record 18; TecText@1000000004 : TextConst 'ENU=Are you sure you want Merge Customer %1 into Customer %2'; Customer2@1000000007 : Record 18; CommentLine@1000000003 : Record 97; CommentLine2@1000000005 : Record 97; CommentLine3@1000000006 : Record 97; DefaultDim1@1000000008 : Record 352; BEGIN END. } }
Comments
Do we need to put new Customer.No. into Customer No. field in Cust. Ledger Entry table?
This is such a cool idea and it might help me with s lot of small things at work! \:D/
Best,
CouberPu
No you don't. Navision will automatically do it for you.
Yep it's a great idea,
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Henrik Ohm
It will be automatically changed when Navision does the rename.
AP Commerce, Inc. = where I work
Getting Started with Dynamics NAV 2013 Application Development = my book
Implementing Microsoft Dynamics NAV - 3rd Edition = my 2nd book
It's nice to see random "thank you" in your old posts.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
|To-Increase|
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
"Show All..."
"Oh..."
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I have tried your code and it worked so great. Thank you very much.
BTW, before finding your post I unsuccessfully tried to merge customers using standard NAV functionality: Customer Card > Customer > Combine Customers. Got too many difficulties...
Best Regards
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
http://ssdynamics.co.in
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I need to merge a number of vendor accounts and have a number of questions
1) Will it work in Nav 2009?
2) Do I need to replace Customer with Vendor in the Code?
Many thanks for you help
Yes to all your questions.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Noticed that it leaves data behind in the following tables:
[dbo].[TEST$Comment Line].[Comment]
[dbo].[TEST$Purch_ Inv_ Header].[Invoice Disc_ Code]
[dbo].[TEST$Vendor Bank Account].[Code]
[dbo].[TEST$Vendor].[BACS Account No_]
[dbo].[TEST$Vendor].[Invoice Disc_ Code]
In fact the merged to account ends up with the vendor Bank And Inv Disc code belonging to the deleted vendor
Many Thanks
You'll need to add them to your routine.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I do not seem to be able to retrieve the bank account details
VendorBank.GET(VendorNo1); fails
as does
VendorBank.GET(VendorNo1; VendorNo1);
Where VendorBank is a record linked to Vendor Bank Account table (288)
Try VendorBank.get(Vendor.Code,BankCode)
with best regards
Jens
Does it matter that there will be orphaned Purchase Invoices / credit memos?
Clearly the rename function ingnores them
Regards
1) Retains the Merged To account details
2) Removes the Merged From Vendor Bank account record
I have a small query
While renaming customer system is generating error
//*********************//
The Customer Bank Account already exists.
Identification fields and values:
Customer No.='20000',Code='ECA'
//***********************//
What system is doing is correct but as the code stops at
Customer.GET(CustomerNo1);
Customer2 := Customer;
Customer.RENAME(CustomerNo2);
** CustomerNo1 = Customer to be deleted
** CustomerNo2 is the customer into which records are to be mergerd.
Should i write the code to modify customer ledger entry & other tables or some modification is required in above written code?
Please help..
Thanks in advance
Prateek
It was my mistake actually the error was for Customer bank accounts..
I am just wondering what is the use of these bank accounts..... presently i deleted the customer bank account entry and it worked out.
That's why you need to check all the tables that might be related to the table you are merging the records (customer/vendor/gl account/bank account, etc.) and ensure that the field that links to the table where you are merging the records has the "tablerelation" property set OR in the code modify/rename those records.
There are problems also when you have records in related tables (like comments, prices,etc) where the records might, after being renamed, have the same key as the existing records for the record you merge into, so you might want to review those and manually rename those records first (or the automatic renaming will give you an error).
Would this report work for NAV 2015 and does it bring all of the customer 1 history to customer 2? Does the customer 2 retain it's customer number?
If this proc report does work in NAV 2015, can someone export this as a fob so that I could import and use? (as an end user (IT, but no developer license) I cannot import txt files)
I can try to get our VAR to install it for us, but would rather just import a fob if one is available.
Thanks in advance.
Hi Great Example... Do you have the same report for NAV 2013 r2. It would really be helpful.
Thanks