XMLPort - Variable Length file and modifying value

kazakaza Member Posts: 9
I am using a XMLPort to import a variable length file. The property Format is set to varialbe Text. The propery Direction
is set to import.

The table into which I am importing the variable length file has the primary key of "ID".

This ID value is NOT contained in the file that is to be imported. I, therefore, generate a unique ID and need to insert this into the record - (before the values from the file are imported) in order to make the record unique.

I am trying to apply the same principles as I have done for a dataport (which works fine). But I cannot seem to get the XMLPort to work. (if I add a unique ID as the first element in the file - and do a "straight" import - then the XMLPort works great) - but when I try to programmatically generate a unique Id and then added this to "imported" file, then I have a problem.

I keep getting the following error - "The XMLParser return the following fata error; Incorrect Document Syntax. Line Number=1. Column Number = 1."

I have tried numerous ways to solve the problem...but keep getting the above error.

The variable length file contains that following data
2011 3 38224 FIN56
2011 3 38224 FIN56
2011 3 38224 FIN56
2011 3 38224 FIN56

I am not sure which syntax I should use for the XMLPort - ans have encluded both ways that I have tried.
Please advise which syntax I should use (or neither?) - given the above file...

Root Element Text <Root>
WABillingEntry Element Table <WA Billing Entry>(WA Billing Entry)
Year Element Field <WA Billing Entry>::Year
Month Element Field <WA Billing Entry>::Month
ClientID Element Field <WA Billing Entry>::Client ID
Code Element Field <WA Billing Entry>::Code

OR
in the following syntax, I have added the field of ID - as this is the field in the table that must contain a unique value.

Root Element Text <Root>
WABillingEntry Element Table <WA Billing Entry>(WA Billing Entry)
ID Element Text <ID>
Year Element Field <WA Billing Entry>::Year
Month Element Field <WA Billing Entry>::Month
ClientID Element Field <WA Billing Entry>::Client ID
Code Element Field <WA Billing Entry>::Code

I have added the following code in the triggers. Please advise into which trigger the code must go if I have it incorrect.

//**********************************
WABillingEntry - Import::OnBeforeInsertRecord()
//***********************************
gintID +=1;
"<WA Billing Entry>".VALIDATE(ID,gintID);
"<WA Billing Entry>".INSERT(TRUE);

Appreciate any help
Thanks
k

Comments

  • jlandeenjlandeen Member Posts: 524
    Typically when I am programitcally assigning values and inserting records I do NOT use a record variable in the XML port and us all text variables for data items. This should allow you to intercept each value as it comes in and process it however you want or need too. This can be time consuming to map all the fields and write code to handle the record insertion....but it also allows the most control as NAV is not doing things auto-magically, you the developer have full control over how the transaction runs.

    Then in the WABillingEntry - Import::OnAfterAssignVariable() I read all of the variables out of the different text variables, generate the new record key, populate fields and insert record (along with any other business logic necessary).
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • kazakaza Member Posts: 9
    Thank you very much for your response - I do appreciate it.

    What you have said makes sense - I will give it a try...

    Thanks once again.
    cheers.
    k
  • kazakaza Member Posts: 9
    Greetings,

    I have tried your solution and I have two questions...

    1) I have created the XMLport to look as follows:-

    Root Element Text <Root>
    WABillingEntry Element Table <WA Billing Entrysmall>(WA Billing Entrysmall)
    txtYear Element Text <txtYear>
    txtMonth Element Text <txtMonth>
    txtClientID Element Text <txtClientID>
    txtCode Element Text <txtCode>

    Is the above correct? I was unable to work with ONLY text elements. i.e. I was forced to have a table before it allowed me to create the text elements.

    One of the error messages it gave me when trying to compile all ALL elements of type text was, "If root element has source type text then all other elements must be source type table"

    Is there a property I must set to enable ALL my datatypes to be text?

    ***************

    2) Assuming the above XMLport sysntax is correct then for the element
    WABillingEntry Element Table <WA Billing Entrysmall>(WA Billing Entrysmall)
    there is no trigger called WABillingEntry - Import::OnAfterAssignVariable().

    For the table element, there are only these triggers
    WABillingEntry - Import::OnAfterInitRecord
    WABillingEntry - Import::OnBeforeInsertRecrd.

    What am I doing wrong?

    Hope you can help.
    Cheers
    k
  • kazakaza Member Posts: 9
    Hi there,

    I have solved the issue. Thanks very must for your help.

    I have created the XMLport with the follwoing syntax:-

    Root Element Text <Root>
    WABillingEntry Element Table <WA Billing Entrysmall>(WA Billing Entrysmall)
    txtYear Element Text <txtYear>
    txtMonth Element Text <txtMonth>
    txtClientID Element Text <txtClientID>
    txtCode Element Text <txtCode>

    and then I did as you said, and assigned the txt variables to the record variable. All of this code I wrote in the trigger :-
    WABillingEntry - Import::OnBeforeInsertRecord().


    If you know of any reason why I should not do the programatic manipulation in this trigger - I would welcome your feedback.

    Thanks
    cheers
    k
  • jlandeenjlandeen Member Posts: 524
    That's the trigger that I've been using for these kinds of manipulations for quite some time and I think it works quite well.
    Jeff Landeen - Sr. Consultant
    Epimatic Corp.

    http://www.epimatic.com
  • kazakaza Member Posts: 9
    Thank you once again.

    have great day
    cheers
    k
Sign In or Register to comment.