Trying to use a previously defined variable in "SETRANG

johnsogj
Member Posts: 103
I am creating a report that displays various Item Card information for items where "Kit BOM No." is not blank. For each of these items, the report will go look in the Production BOM Line table and find all component item numbers. I'm fine so far. The problem comes when I need to go back into the item card to look for the on hand quantities for each of those components in the Kit BOM. The code I am trying does not error out, but rather it just displays the on hand quantity for the master item. Here is what I tried:
('kitdetail' is the variable name for the "Production BOM Line" table)
('BOM1' is the variable name for the first component item number. This is the variable for which I want to go find the on hand quantity in the item card.)
KitDetail.SETCURRENTKEY("Production BOM No.", "Version Code", "Line No.");
KitDetail.SETRANGE("Production BOM No.", Item."Kit BOM No.");
KitDetail.SETRANGE("Version Code", ' ');
KitDetail.SETRANGE("Line No.", 10000);
IF KitDetail.FINDFIRST THEN
BOM1 := KitDetail."No."
ELSE BEGIN
BOM1 := 'N/A';
END;
Item.RESET;
Item.SETCURRENTKEY("No.");
Item.SETRANGE("No.", BOM1);
BOMQty1 := Item.Inventory;
('kitdetail' is the variable name for the "Production BOM Line" table)
('BOM1' is the variable name for the first component item number. This is the variable for which I want to go find the on hand quantity in the item card.)
KitDetail.SETCURRENTKEY("Production BOM No.", "Version Code", "Line No.");
KitDetail.SETRANGE("Production BOM No.", Item."Kit BOM No.");
KitDetail.SETRANGE("Version Code", ' ');
KitDetail.SETRANGE("Line No.", 10000);
IF KitDetail.FINDFIRST THEN
BOM1 := KitDetail."No."
ELSE BEGIN
BOM1 := 'N/A';
END;
Item.RESET;
Item.SETCURRENTKEY("No.");
Item.SETRANGE("No.", BOM1);
BOMQty1 := Item.Inventory;
0
Comments
-
IF Item.FINDFIRST THEN BOMQty1 := Item.Inventory;NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
thanks for your quick response! where do I put that line of code? Do I remove any of that second section of code I had written myself?0
-
Look for the line
BOMQty1 := Item.Inventory;
that you posted
then addIF Item.FINDFIRST THEN
before itNAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
Instead of:
Item.RESET; Item.SETCURRENTKEY("No."); Item.SETRANGE("No.", BOM1); BOMQty1 := Item.Inventory;
Do this:IF Item.GET(BOM1) THEN BEGIN Item.CALCFIELDS(Inventory); // because Inventory is a flowfield BOMQty1 := Item.Inventory; END ELSE BEGIN BOMQty1 := 0; END;
The "No." field is the primary key of the Item table, so you don't have to set any filters, you can just use GET, much easier to program.0 -
And then I'd probably combine the code into something like this:
KitDetail.SETCURRENTKEY("Production BOM No.", "Version Code", "Line No."); KitDetail.SETRANGE("Production BOM No.", Item."Kit BOM No."); KitDetail.SETRANGE("Version Code", ' '); KitDetail.SETRANGE("Line No.", 10000); IF KitDetail.FINDFIRST THEN BEGIN BOM1 := KitDetail."No." ; Item.GET(BOM1); Item.CALCFIELDS(Inventory); BOMQty1 := Item.Inventory; END ELSE BEGIN BOM1 := 'N/A'; BOMQty1 := 0; END;
0 -
I tried that whole section of code, but now it is using the first BOM component as the main item - and then it loops continuously. I had to get kicked out in order for it to stop. it just repeats the same line over and over and over. could I have the code in the wrong section? I have it in "On after Get Record".0
-
when I take out this middle piece of code:
Item.GET(BOM1);
Item.CALCFIELDS(Inventory);
BOMQty1 := Item.Inventory
the rest of the report works fine. I just cant get that BOM component quantity in there... any suggestions?0 -
Your main dataitem is probably called Item, so it's constantly going back and forth through the same items. If that's the case, then you need to define another record variable, call it 'MyItem'. in my code snippet, replace all Item with MyItem, and see what that does.
It could very well be in the wrong trigger, but there's no way to tell from here what the actual issue is, without the whole object and what it's supposed to do.0 -
thank you! it worked perfectly. I'm all set now.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