How to avoid duplication when importing invoices?

VesnaVesna Member Posts: 24
Hey everyone,
I need to create a code that prevent the customer from duplication importing the same 1000 invoices.
Right now, I created the following code:
IF ("Document No.") EXIST
Then Begin
CurrDataport. SKIP;
END;

But system gives me an error.
Any suggestions please.
[-o<

Comments

  • SavatageSavatage Member Posts: 7,142
    Have you thought about changing the property on the Sales header dataitem

    AutoUpdate=NO
    AutoReplace=NO
  • DenSterDenSter Member Posts: 8,305
    Vesna wrote:
    IF ("Document No.") EXIST
    Then Begin
    CurrDataport. SKIP;
    END;
    Does that compile?
  • VesnaVesna Member Posts: 24
    to Savatage,
    I created dataport in Purchase Line so when I do
    AutoUpdate=NO
    AutoReplace=NO
    I can not import anything. Our client is going to use this dataport from time to time to import its invocies so customers' No and Names can repeat.
    I need system to identify by invoice No. that this invoice has been already imported. Because if client imports 1000 invoices and then found out that these invocies have been already imported and posted recently, of course it is not fun for him to delete them one by one.

    To DenSter,
    It does not. I thought I saw this somewhere on the forum.
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Where are you importing your data? To the Sales Header table or the Gen. Journal Line table?
  • VesnaVesna Member Posts: 24
    I am importing Purchase invoices through dataport created in Purchase Line
  • SavatageSavatage Member Posts: 7,142
    can we assume you're creating the purchase header using your dataport?

    Hmm - Autoreplace = No always prevents overwriting for me :-k
  • VesnaVesna Member Posts: 24
    Savatage,
    "Hmm - Autoreplace = No always prevents overwriting for me"

    Yes, that is right, but only when invoices not posted yet.
    As soon as I post invoices N.1, N.2, N.3 they disapper.
    When I (let's say mistakenly) import them again. System allows me to do this but when I am trying to post them it tells me that invoices with this Vendor Inovice No. already exist.
    In this case I have to delete all imported invoices (what a huge work if I imported 1000)
    So I want the system to identify by Invoice No. that this invoices have been already imported and posted.
    Thank you
  • SavatageSavatage Member Posts: 7,142
    Ahh that's very different - so you are automatically filling in the Posting No. then instead of letting Nav assign the next available one.
    Your Not using the posted Purchase Invoice No Series.

    So you want to take the Puchase Line Doc No & Search the Purch. Inv Header first to see if it exists first.
  • VesnaVesna Member Posts: 24
    Thank you for the reply Savatage,
    But honestly it is not very clear to me.
    Can you give me a hint of C/AL code for it.
    Highly appreciate
    Vesna
  • SavatageSavatage Member Posts: 7,142
    Are you using variables to load your data?

    How About

    OnAfterImportRecord()
    IF "Purch. Inv. Header".GET("Purchase Line".Document No.")
    THEN CurrDataport.SKIP
    ELSE BEGIN
    .. All the rest
    END;
    
  • VesnaVesna Member Posts: 24
    Thank you Savatage,
    Yes, I am using variables to import my data.
    Now, I realise that it better if I will use Vendor Invoice No. as identified point, because this number remained the same when invoice is posted, while Document No can be changed by the system according to N. Serial for Posted Purchase Invoices.
    So on the basis of your code I tryed different combination but it doesn't work for me. :cry: ](*,)
    The dataport accept the following code:
    PurchaseHeaderRec.RESET;
    If PurchaseHeaderRec. GET(VIN)
    Then begin
    CurrDataport.SKIP;
    END;
    where VIN is my variable for Vendor Invoice No.
    But when I am trying to import file I see the message "The expression Text cannot be type-converted to a Option value"
    If there are any ideas I appreciate greatly because I already have doubts that there is a solution for this.
    :roll:
  • SavatageSavatage Member Posts: 7,142
    The expression Text cannot be type-converted to a Option value"

    There must be more code than you're showing us.
    What is VIN again? the Posted Purch Inv No? or some Order No? or something?
    is VIN a key?
    If PurchaseHeaderRec.GET(VIN) 
    Then begin 
    CurrDataport.SKIP
    End
    Else Begin 
    ..
    <Mapping of variables happening here>
    ..
    END;
    

    Is PurchaseHeaderRec a Variable for The Purchase Header or Purchase Inv Header?
  • SavatageSavatage Member Posts: 7,142
    edited 2008-02-21
    we import Orders and on import of the The Order# I also added
    SalesHeader."Posting No" := varOrderNo;
    SalesHeader."Shipping No" :=varOrderNo;

    This way on posting all the Numbers match all the way thru from order to invoice.
    This code works for us to prevent the duplication of imported orders.
    IF SalesInvHeader.GET(varOrderNo) 
    THEN CurrDataport.SKIP 
    ELSE BEGIN 
    .. All the rest 
    END;
    

    If your not going to use the key - then I think a FIND function is needed
  • BeckaBecka Member Posts: 178
    keep numberin'....

    good luck :mrgreen:
    MCSD
    Attain Navision
Sign In or Register to comment.