Dataport, rec and xrec variable???

nverma
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???
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??
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??
0
Comments
-
you need to use IF GET THENDavid Singleton0
-
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.0 -
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 exists0 -
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);
0 -
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;0 -
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.0 -
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;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions