Dataport, rec and xrec variable???

nvermanverma Member Posts: 396
I have created a dataport (import), which is going to save data to different tables (customer, vendors, job) at the same time.

Right now, I am getting an error that a particular customer type already exists. So, I tried writing a condition statement to take care of it but its didnt work.

It said i have specified an unknown variable, rec and xrec. How can i check it without using the rec and xrec variable. Thats what I have always used to do these sorta checks???
IF rec.Customer."No." = xrec.Customer."No." THEN
Customer.MODIFY(true);


So basically what I want to do is, check if a particular Customer."No." exists in records. If it does, then modify it to import the information from the one in the excel file.

Any suggestions??

Comments

  • David_SingletonDavid_Singleton Member Posts: 5,479
    you need to use IF GET THEN
    David Singleton
  • nvermanverma Member Posts: 396
    I tried what you suggested.
    IF Customer.GET("No.") THEN
    Customer.Modify(TRUE);
    

    It gives me the same message. That a particular customer number already exist.

    I just want it to modify it, even if it already exists in record and AutoReplace doesnt work because I am importing to multiple tables at the same time.
  • SavatageSavatage Member Posts: 7,142
    So you have set AutoReplace to NO & AutoUpdate to YES?

    Is that all your code?
    do you have an INSERT somewhere?

    Are you importing into variables & mapping back to nav fields or are you going direct to nav fields?
    particular customer type already exists
    What other type of customer is there? :-k
  • nvermanverma Member Posts: 396
    This is all the code I have for Customer table. It is written it in OnAfterImportRecord() trigger. I have set AutoUpdate, AutoReplace, AutoSave to YES.
    Customer.INIT;
    
    IF Customer.GET("No.") then 
    Customer.MODIFY(TRUE);
    
    
    Customer."Client Type" := Customer."Client Type"::Consumer;
    
    
    Customer."First Name" := clfname;
    Customer.Initial := clmname;
    Customer."Last Name" := cllname;
    Customer."Birth Date" := cldob;
    
    IF clgender = 'M' THEN
        Customer.Gender := Customer.Gender::Male
    ELSE
      Customer.Gender := Customer.Gender::Female;
    
    Customer.Address := claddress1;
    Customer."Address 2" := claddress2;
    Customer.City := clcity;
    Customer.County := clprovince;
    Customer."Post Code" := clpostalcode;
    Customer."Phone No." := clphone;
    Customer.INSERT(TRUE);
    
  • SavatageSavatage Member Posts: 7,142
    I'm not really following your code.

    You start off with modify then you assign all these variables then insert?
    what exactly are you modifying at that point?

    why not group them with if--then begin--end else begin--end?
    because if you don't group it with a condition the insert line is going to run if you like it or not.
    and give you an error if it already exists.

    or lose the first modify & change the last insert line to

    if not insert then modify;

    you have to be careful with autoreplace - because "i believe" it will clear out any fields you are not defining instead of just updating a few fields.

    now if this basically an insert dataport you can use
    if customer.get("no.") then begin
    currdataport.skip;
    end else begin
    .
    .
    .
    insert; //not even sure you need to tell it to insert if you have your auto.. properties set correctly.
    end;
  • nvermanverma Member Posts: 396
    Basically, what I am trying to do is:

    1) Check if the Customer No. exists. If it does, replace the information in that record with the new information from the excel file. Hence the Modify function.

    2) Even if the Customer No. does not exist. Create a new record and initialize all the information from the excel file to the fields in the table.

    One of the heading in my excel file was clfname, which got mapped to Customer."First Name". Hence this line of code: Customer."First Name" := clfname; ..... and so on.


    The exact Error That I am getting right now is this:
    "Customer C1XXXXXX already has a contact business relation with contact CTXXXXXX"

    The way I interpret this error was that, this record already exists in the system. Thats why, I wanted to write the If condition to modify the information even if the record exists.
  • j.marseloj.marselo Member Posts: 102
    often, it's done like this:

    //assignments to keys, e.g.
    customer."no." := 'XXX'; //or
    vendor."no." := 'YYY'; // and so on

    IF INSERT THEN BEGIN

    {this is to place your action when it sucessfully inserting new customer no. or new vendor no.}
    ... // your statements

    END ELSE BEGIN

    {this is to placeyour action when it CANNOT insert, means, "No." is already exist}
    ... // your statements

    END;
    Kind regards, Joe Marselo | see my NAV blog joemarselo.wordpress.com | twitter @joemarselo
Sign In or Register to comment.