Lookup Issue

souravb
Member Posts: 135
Hi,
I have a code which is creating a problem:
IF Type=0 THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher Type","Voucher Type");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher No.","Voucher No.");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
IF GVVoucherHdr."Account Type"=5 THEN
BEGIN
IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN
BEGIN
"No.":=GLAcc."No.";
Description:=GLAcc.Name;
END;
END;
END;
END;
END;
If the user selects Type 0(line level) and Account Type 5(in Header level)
then the G/L Account list form will open. Type 0 is G/L Account. I wrote the code in the OnLookup of No. field. The code is not working. Can anybody help
I have a code which is creating a problem:
IF Type=0 THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher Type","Voucher Type");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher No.","Voucher No.");
IF GVVoucherHdr.FIND('-') THEN
BEGIN
IF GVVoucherHdr."Account Type"=5 THEN
BEGIN
IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN
BEGIN
"No.":=GLAcc."No.";
Description:=GLAcc.Name;
END;
END;
END;
END;
END;
If the user selects Type 0(line level) and Account Type 5(in Header level)
then the G/L Account list form will open. Type 0 is G/L Account. I wrote the code in the OnLookup of No. field. The code is not working. Can anybody help
0
Comments
-
Use debugger, indent your code, there is no need to find the record twice.0
-
souravb wrote:
IF Type=0 THEN BEGIN GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher Type","Voucher Type"); IF GVVoucherHdr.FIND('-') THEN BEGIN GVVoucherHdr.SETRANGE(GVVoucherHdr."Voucher No.","Voucher No."); IF GVVoucherHdr.FIND('-') THEN BEGIN IF GVVoucherHdr."Account Type"=5 THEN BEGIN IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN BEGIN "No.":=GLAcc."No."; Description:=GLAcc.Name; END; END; END; END; END;
1:
don't do IF Type=0... that's not very nice to read. What is much nicer to read is to specify the type explicitlyIF Type = Type::"G/L Account"
2:
Why are you nesting all of these IF statements? It looks like you're trying to find a record, so why not just set filters? There is no point in finding records more than once. Just set all the filters and THEN try to retrieve the values. By the way, if you're setting filters on a record variable, you don't have to specify the record variable again in the filter declaration. I'm not even trying to figure out what your code means, but clean it up to look something like this:GVVoucherHdr.SETRANGE("Voucher Type","Voucher Type"); GVVoucherHdr.SETRANGE("Voucher No.","Voucher No."); GVVoucherHdr.SETRANGE("Account Type","Account Type"::"Value 5"); IF FORM.RUNMODAL(18,GLAcc)=ACTION::LookupOK THEN "No.":=GLAcc."No."; Description:=GLAcc.Name; END;
3:
What you really want to do though, is set a conditional table relation on the "No." field. Check out the Sales Line table for an example. You can specify a relationship to a different table based on the value of another field. You don't need all that code!!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