Options

Error while importing XML file

NRNR Member Posts: 78
I am importing an xml file through the XMLport.

While importing, an error is flashed: "The text "......" is too long. Text can have a maximum length of 50 characters."

How should I truncate the characters prior to importing ?

Thanks in advance

Comments

  • Options
    alok_didaalok_dida Member Posts: 73
    NR wrote:
    I am importing an xml file through the XMLport.

    While importing, an error is flashed: "The text "......" is too long. Text can have a maximum length of 50 characters."

    How should I truncate the characters prior to importing ?

    Thanks in advance
    You can check your string value in this trigger Import::OnBeforeInsertRecord().

    In this u have to check string length using STRLEN(fieldname).. and if it is greater than 50 than it depends on u what operation u have to do. Normally people taking initial 50 characters and you can do it using function COPYSTR(fieldname,1,50) and assign this value to that fieldname only.

    for example


    IF STRLEN(fieldName) > 10 THEN BEGIN
    tableName.fieldName := COPYSTR(fieldName,1,10);
    END
    ELSE BEGIN
    tableName.fieldName := fieldName;
    END;
  • Options
    NRNR Member Posts: 78
    I added the following C/AL in OnBeforeInsertRecord of the XMLport:

    IF STRLEN("<Invoice>".Agency) > 50 THEN
    "<Invoice>".Agency := COPYSTR("<Invoice>".Agency,1,50);

    But, still it flashes the same error.
  • Options
    alok_didaalok_dida Member Posts: 73
    NR wrote:
    I added the following C/AL in OnBeforeInsertRecord of the XMLport:

    IF STRLEN("<Invoice>".Agency) > 50 THEN
    "<Invoice>".Agency := COPYSTR("<Invoice>".Agency,1,50);

    But, still it flashes the same error.
    Are you importing XML file or Text file?
  • Options
    krikikriki Member, Moderator Posts: 9,098
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    NRNR Member Posts: 78
    It's an XML file.

    Following are the properties of the Agency field in the XMLport which is giving an error:

    Indentation 1
    NodeName Agency
    NodeType Element
    SourceType Field
    SourceField <Invoice>::Agency
    FieldValidate <Undefined>
    AutoCalcField <Yes>
    Width 0
    MinOccurs <Once>
    MaxOccurs <Once>

    Do I need to change the SourceType to Text and assign the field through C/AL?
  • Options
    alok_didaalok_dida Member Posts: 73
    Can u please debug ur code?


    And can u see what's value is coming there in Agency field?

    try following code

    IF STRLEN(Agency) > 50 THEN
    "<Invoice>".Agency := COPYSTR(Agency,1,50)
    ELSE
    "<Invoice>".Agency := Agency;
  • Options
    NRNR Member Posts: 78
    On debugging, the error is invoked immediately after execution of XMLPORT.IMPORT(50075,TestStream) in the Codeunit.

    Specifying Agency instead of <Invoice>.Agency given an unknown vairable error.
  • Options
    alok_didaalok_dida Member Posts: 73
    NR wrote:
    On debugging, the error is invoked immediately after execution of XMLPORT.IMPORT(50075,TestStream) in the Codeunit.

    Specifying Agency instead of <Invoice>.Agency given an unknown vairable error.
    Did u put any breakpoint on that If condition?

    Its giving error in CodeUnit? I didnt get u..
  • Options
    NRNR Member Posts: 78
    I debugged with breakpoint on triggers.

    After the xmlport is called from codeunit, and xmlport is initialized, it gives the error.
  • Options
    alok_didaalok_dida Member Posts: 73
    NR wrote:
    I debugged with breakpoint on triggers.

    After the xmlport is called from codeunit, and xmlport is initialized, it gives the error.
    Is it possible for u to send me ur XMLPort and XML File ? so that i can check on my local PC..
  • Options
    pduckpduck Member Posts: 147
    Maybe a false encoding so that elements did not be recognized well? Which encoding has your xml?
  • Options
    kinekine Member Posts: 12,562
    If the text in the tag is longer than the target variable (in this case some field), you cannot "Trim" the value before it is assigned to the field. You need to use text variable instead field as target and assign the value to the field manually in the OnAfterAssignVariable trigger of the tag.

    Right now, the error is risen right when the value should be assigned to the field and there is no trigger before this action (like OnBeforeEvaluateField in dataport).
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.