Using setrange in report.

IPGRussIPGRuss Member Posts: 12
I have a report that uses the Item Ledger Entry line and I need to pull some information from the Item table at the same time. I'm trying to use setrange to accomplish this but I think I'm missing something:
"Item".SETRANGE("Item Ledger Entry"."Item No.");
IF "Item".FIND('-') THEN BEGIN
  rootcost := "Item"."Material Cost";
END;


Thanks in advance for any help.

Comments

  • ar4ijsar4ijs Member Posts: 24
    Use Item.GET instead of SETRANGE and FIND:
    IF Item.GET("Item Ledger Entry"."Item No.") THEN 
      rootcost := Item."Material Cost";
    
  • JedrzejTJedrzejT Member Posts: 267
    Hi,

    If You do it in trigger - On AfterGetRecord in dataitem "Item ledger entry" then code should be:

    IF "Item".GET("Item ledger entry"."Item No.") THEN
    rootcost := "Item"."Material Cost"
    ELSE
    rootcost :=0; //probably never use - You can delete this line

    There is more other solution to do this ,but this will work.
    Regards
  • DaveTDaveT Member Posts: 1,039
    Hi,

    The setrange needs at least two parameters to work e.g. setrange( Onwhat, RangeValue,... )

    Because you're looking up a table which the code is a primary key

    the following code would be better
    if item.get("Item Ledger Entry"."Item No.") then
      rootcost := Item."Material Cost"
    else
      rootcost := 0;
    

    Hope this helps
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • IPGRussIPGRuss Member Posts: 12
    It comes back saying Material Cost is not defined. I have Item defined in my globals as record of the Item table. Do I need to define this field somewhere else?
  • DaveTDaveT Member Posts: 1,039
    I thought it was a field you added. Use Item."unit cost". To find out all fields on a record use the C/AL Symbol Menu (F5)
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • IPGRussIPGRuss Member Posts: 12
    I did create Material Cost, had a typo, it's working now, thanks.
  • IPGRussIPGRuss Member Posts: 12
    So it's now pulling the correct value for Material Cost but now, if Material Cost = 0 it should pull the Cost Amount from the Item Ledger Entry, this just returns 0:
    IF item.GET("Item Ledger Entry"."Item No.") THEN
      rootcost := item."Material Cost (FYI)"
    ELSE
      rootcost := "Item Ledger Entry"."Cost Amount (Actual)"
    
  • IPGRussIPGRuss Member Posts: 12
    I realized I wasn't checking to see if the Material Cost = 0, I am now, but this doesn't seem to be working:
    IF item.GET("Item Ledger Entry"."Item No.") THEN
      IF item."Material Cost (FYI)" = 0 THEN
        rootcost := item."Material Cost (FYI)"
      ELSE
        rootcost := "Item Ledger Entry"."Cost Amount (Actual)";
    
    roottotal := roottotal + rootcost;
    
    
  • DaveTDaveT Member Posts: 1,039
    Hi

    You have your "if" the wrong way around if cost = 0 then root = cost.

    should be

    if cost = 0 then
    root := item ledger entry
    else
    root := cost;
    Dave Treanor

    Dynamics Nav Add-ons
    http://www.simplydynamics.ie/Addons.html
  • ar4ijsar4ijs Member Posts: 24
    Did you call CALCFIELDS for "Item Ledger Entry"."Cost Amount (Actual)" ?
Sign In or Register to comment.