mibuso.com

Microsoft Business Solutions online community
It is currently Thu Jun 20, 2013 1:21 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 6:33 pm 
Offline

Joined: Fri Sep 30, 2011 7:04 pm
Posts: 298
Country: Canada (ca)
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???

Code: Select all

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??


Top
 Profile E-mail  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 6:50 pm 
Offline
MVP Microsoft Dynamics NAV
NAV TechDays 2013 attendee

Joined: Tue Aug 14, 2001 7:01 am
Posts: 5317
Location: Prague
Country: Czech Republic (cz)
you need to use IF GET THEN

_________________
David Singleton
Dynamics NAV Freelancer
Dynamics Book
Go-Live International


Top
 Profile E-mail WWW  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 7:03 pm 
Offline

Joined: Fri Sep 30, 2011 7:04 pm
Posts: 298
Country: Canada (ca)
I tried what you suggested.

Code: Select all
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.


Top
 Profile E-mail  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 8:35 pm 
Offline
MVP Microsoft Dynamics NAV
Site Supporter

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 6992
Location: L.I., New York
Country: United States (us)
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?

Quote:
particular customer type already exists

What other type of customer is there? :-k

_________________
Harry Ruiz
http://www.cosmeticsolutions.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 10:58 pm 
Offline

Joined: Fri Sep 30, 2011 7:04 pm
Posts: 298
Country: Canada (ca)
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.

Code: Select all
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);


Top
 Profile E-mail  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Wed Mar 14, 2012 11:40 pm 
Offline
MVP Microsoft Dynamics NAV
Site Supporter

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 6992
Location: L.I., New York
Country: United States (us)
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;

_________________
Harry Ruiz
http://www.cosmeticsolutions.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Thu Mar 15, 2012 3:38 am 
Offline

Joined: Fri Sep 30, 2011 7:04 pm
Posts: 298
Country: Canada (ca)
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.


Top
 Profile E-mail  
 
 Post subject: Re: Dataport, rec and xrec variable???
PostPosted: Thu Mar 15, 2012 5:06 am 
Offline

Joined: Tue Jul 03, 2007 10:39 am
Posts: 86
Location: Jogjakarta
Country: Indonesia (id)
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


Top
 Profile E-mail WWW  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: Google [Bot], johan_bosma and 29 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: