XML import Customer list problem

remarkremark Member Posts: 122
I try to import a customer list via XML port to Table 18 Customer and get a following massage:
"Customer K00110 has already Contact Business Relation with Contact CT00170"
and no lines are put in the Customer Table.

There isn't both Customer K00110 and Contact CT00170 in the database.

Please, help me to solve this.

Comments

  • remarkremark Member Posts: 122
    After multiple attempts it seems that it's impossible insert even one line with the only field filled ("No.") because of some link with the table Contacts.
    The same XML port inserts lines seccessfully in another table, which were created for these testing purposes.

    Is it impossible to import Customer list with the help of XML port altogether?
  • ara3nara3n Member Posts: 9,256
    Could you post your xmlport and xml file example.

    I believe it's one of your validation that causes the issue.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    This is the structure of the XML port:

    TagName TagType SourceType DataSource
    Customers Element Text <Customers>
    Customer Element Table <Customer>(Customer)
    No. Element Field <Customer>::No.
    Name Element Field <Customer>::Name
    SearchName Element Field <Customer>::Search Name
    Address Element Field <Customer>::Address
    City Element Field <Customer>::City
    PostCode Element Field <Customer>::Post Code


    This is a sample of some lines from XML file:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Customers>
    <Customer>
    <No.>K00050</No.>
    <Name>SomeName</Name>
    <SearchName>SOMENAME</SearchName>
    <Address>SomeAddress</Address>
    <City>SomeCity</City>
    <PostCode>109000</PostCode>
    </Customer>
    <Customer>
    <No.>K00060</No.>
    <Name>SomeName2</Name>
    <SearchName>SOMENAME2</SearchName>
    <Address>SomeAddress2</Address>
    <City>SomeCity</City>
    <PostCode>109000</PostCode>
    </Customer>
    </Customers>

    This is code from Dubugger. These lines are from OnInsert trigger of Table 5054 Contact Business Relation.

    OnInsert()
    IF "No." <> '' THEN BEGIN
    ContBusRel.SETRANGE("Contact No.","Contact No.");
    ContBusRel.SETRANGE("Link to Table","Link to Table");
    IF ContBusRel.FIND('-') THEN
    ERROR(
    Text000,
    Cont.TABLECAPTION,"Contact No.",TABLECAPTION,"Link to Table",ContBusRel."No.");

    ContBusRel.RESET;
    ContBusRel.SETCURRENTKEY("Link to Table","No.");
    ContBusRel.SETRANGE("Link to Table","Link to Table");
    ContBusRel.SETRANGE("No.","No.");
    IF ContBusRel.FIND('-') THEN
    ERROR(
    Text000,
    "Link to Table","No.",TABLECAPTION,Cont.TABLECAPTION,ContBusRel."Contact No.");

    Here it stops with that error. ](*,)

    The XML file is large, so I've made a simplified extract from it in order that this post could be readable.
  • remarkremark Member Posts: 122
    Sorry, after posting all the indents are lost and the structure of port became different.
    I must learn how to insert code in posts.
  • remarkremark Member Posts: 122
    Second attempt.

    This is code from Debugger:
    OnInsert()
    IF "No." <> '' THEN BEGIN
      ContBusRel.SETRANGE("Contact No.","Contact No.");
      ContBusRel.SETRANGE("Link to Table","Link to Table");
      IF ContBusRel.FIND('-') THEN
        ERROR(
          Text000,
          Cont.TABLECAPTION,"Contact No.",TABLECAPTION,"Link to Table",ContBusRel."No.");
    
      ContBusRel.RESET;
      ContBusRel.SETCURRENTKEY("Link to Table","No.");
      ContBusRel.SETRANGE("Link to Table","Link to Table");
      ContBusRel.SETRANGE("No.","No.");
      IF ContBusRel.FIND('-') THEN
        ERROR(
          Text000,
          "Link to Table","No.",TABLECAPTION,Cont.TABLECAPTION,ContBusRel."Contact No.");
    
  • remarkremark Member Posts: 122
    Well, this is XML file:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Customers>
    	<Customer>
    		<No.>K00050</No.>
    		<Name>SomeName</Name>
    		<SearchName>SOMENAME</SearchName>
    		<Address>SomeAddress</Address>
    		<City>SomeCity</City>
    		<PostCode>109000</PostCode>
    	</Customer>
    	<Customer>
    		<No.>K00060</No.>
    		<Name>SomeName2</Name>
    		<SearchName>SOMENAME2</SearchName>
    		<Address>SomeAddress2</Address>
    		<City>SomeCity</City>
    		<PostCode>109000</PostCode>
    	</Customer>
    </Customers>
    
  • remarkremark Member Posts: 122
    What about XML port I need some advise how I could post it.
    In my upper post I simply copy_pasted it from Object Designer. But it doesn't look readable.
  • ara3nara3n Member Posts: 9,256
    export it to text and then paste it.
    Also could you paste the CallStack.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    I created the xmlport and used your xml to import it without any issues.
    My guess your xmlport is creating contacts.

    I suggest that you add the following code to xmlport
    Customer - Import::OnBeforeInsertRecord()
    
    Customer.SetInsertFromContact(TRUE);
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    ara3n wrote:
    I created the xmlport and used your xml to import it without any issues.
    My guess your xmlport is creating contacts.

    I suggest that you add the following code to xmlport
    Customer - Import::OnBeforeInsertRecord()
    
    Customer.SetInsertFromContact(TRUE);
    

    I tried, but it didn't work.
    Concerning xmlport creating contacts, the fact is records are created in tables 5054 Contact Business Relation and 5050 Contact not by xmlport only, this happens always when we add new customer by hand.
  • remarkremark Member Posts: 122
    ara3n wrote:
    export it to text and then paste it.
    Also could you paste the CallStack.

    Unfortunatley, I can't export xmlport in text format, only in .fob. I have such choice in export window, but after trying it I get system message that I can't do it. It connected maybe with licensing issues.

    My code for running xmlport following (I use codeunit in report because I can't create standalone codeunit. I have no 7200 granule Application Builder):
    Customer - OnAfterGetRecord()
    IF NOT EXISTS('C:\XML_Customer.xml') THEN
       ERROR('XML Document File Does Not Exists');
    
    TestFile.OPEN('C:\XML_Customer.xml');
    TestFile.CREATEINSTREAM(TestStream);
    XMLPORT.IMPORT(50001,TestStream);
    TestFile.CLOSE;
    MESSAGE('XML Customer Import Complete.');
    

    And I inserted as you had suggested code in the codeunit of the xmlport:
    Customer - Import::OnBeforeInsertRecord()
    Customer.SetInsertFromContact(TRUE);
    
  • ara3nara3n Member Posts: 9,256
    Can you write the callstack when it errors out?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    ara3n wrote:
    Can you write the callstack when it errors out?

    I'm sorry, I didn't quite understand, what you mean :oops:
    Would you, please, explain it in some details.
    Sorry!
  • ara3nara3n Member Posts: 9,256
    call stack is a special stack which stores information about the active subroutines of a computer program. (The active subroutines are those which have been called but have not yet completed execution by returning.

    Basically a list of triggers until it reaches the error.
    It tells you how it calls the trigger and gives you error.


    It's a separate window in debugger. Over over the 4 windows in debugger and one of it is the calls stack.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    Thank you!

    Here it is:

    Table 5054 Contact Business Relation\OnInsert()
    Codeunit 5056 CustCont-Update\InsertNewContact(Cust,LocalCall)
    Codeunit 5056 CustCont-Update\OnInsert(Cust)
    Table 18 Customer\OnInsert()
    Report 50001 XMLrun\Customer - OnAfterGetRecord()
  • remarkremark Member Posts: 122
    Report 50001 "XMLrun" is here for only purpose to run XMLport.

    I use codeunit in report because I can't create standalone codeunit. I have no 7200 granule Application Builder
  • ara3nara3n Member Posts: 9,256
    Try

    Customer - Import::OnAfterInitRecord()
    Customer.SetInsertFromContact(TRUE);

    in xml port;


    if it doesn't work, try and set in "Relationship Management Setup" the field
    "Bus. Rel. Code for Customers" to blank.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    Thank you, ara3n!

    Yes, it helped to solve problem with the Contacts, but now yet another problem appeared:

    After I run XMLport, I get a message "XML Customer Import Complete", then, after it is closed I get another message: "Customer No. XXX exists already". After that I see, that nothing is imported in Customer Table.

    "No. XXX" is the first "No." in the XMLport. And such number doesn't exist in Customer Table neither before importing no after it.

    In this case debugger doesn't show any error.
  • ara3nara3n Member Posts: 9,256
    Does the customer exists?

    XML ports can only insert records. You have to write code to manually update if customer already exists.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    Customer doesn't exist.

    :-k
  • ara3nara3n Member Posts: 9,256
    Your xmlport works. Your xml file probably has the same customer number twice in there.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • remarkremark Member Posts: 122
    Ara3n, Thank you very much for your patience.
    My XMLport really works.
    The problem was caused by the way in which I run my Report 50001 "XMLrun" with the xml running code.

    Only your assurance that everything with my XMLport is OK helped me to find the real cause. I was looking for bug in the wrong place.
    Thank you for leading me through this way! :D
  • ara3nara3n Member Posts: 9,256
    You are welcome, and thanks for your patience :)
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.