Open Forum

Expand all | Collapse all

lookup value from item record in invoice

  • 1.  lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 18 days ago
    Hi All

    I'm working on a report in C/AL and need to get a field (from an add-in ) fromt he item record

    Field is called "Container Code"

    i created a global var of type Code 10 called gContainerCode

    I then created a local var called recItem in "Line - OnAfterGetRecord()"

    I then added this code

    //find the item record whose no matches invoice line's item no 

    recItem.SETRANGE("No.",Line."No."); 

    // if a record found, get the container code, else return nothing

    IF recItem.FINDFIRST THEN

      gContainerCode := recItem."Container Code"

    ELSE

      gContainerCode := '';


    I don't get any errors :-)

    but i don't get a value either :-(

    Anyone got any ideas?

    Thanks

    Mark



    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------
    Conference-BCNAVUG_200x200


  • 2.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 18 days ago
    Your code looks like it would work....So next step is to use the debugger. Maybe that particular item doesn't have a container code? Maybe the "Line" record isn't an item line or doesn't yet have the "No." field populated. With the debugger you should be able to figure out what's not working.
    Also, (just a tip) rather than using SETRANGE and then FINDFIRST, it would be more efficient in this case to just use:
    IF recItem.GET(Line."No.") THEN ... ELSE ...;

    ------------------------------
    Greg Enns
    ERP Coordinator
    Technical Prospects
    Kaukauna WI
    ------------------------------

    Conference-BCNAVUG_200x200


  • 3.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 17 days ago
    Thanks Greg

    Came in next morning and it seemed to work

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


  • 4.  RE: lookup value from item record in invoice

    Posted 18 days ago
    Hi Mark,

    Two things.  Your code should work fine, but if you have the primary key value, you can use a GET statement:

    CLEAR(gContainerCode);
    IF recItem.GET(Line."No.") THEN
      gContainerCode := recItem."Container Code";

    If that doesn't work, check that the Item you're looking at has a valid Container Code.  If it does, try running the debugger and see if the Line record has the correct "No." value when your code is executing.

    ------------------------------
    Andrew Drott
    ERP Lead
    Gogo, LLC
    Broomfield CO
    ------------------------------

    Conference-BCNAVUG_200x200


  • 5.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 17 days ago
    Thanks Andrew

    Came in next morning and it worked. Thanks for tip on "GET"

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


  • 6.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 17 days ago
    Short follow up, if I need to get 3 fields from the same item record, what would be most efficient way?

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


  • 7.  RE: lookup value from item record in invoice

    Posted 17 days ago

    I would just get the Item record, then reference the fields directly (i.e. recitem."No.", recItem.Description, recItem."Container Code").

     

    You'd only really need to use a variable to store the values if you want to manipulate them or use it at a later time outside the OnAfterRecord trigger.

     

    Andrew Drott  ERP Lead Developer
    Gogo Business Aviation  |  105 Edgeview Drive  |  Broomfield, CO 80021  |  USA  |  O: +1 303 301 3320  |  M: +1 312 231 8085

     




    Conference-BCNAVUG_200x200


  • 8.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 16 days ago
    Thanks Andrew

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


  • 9.  RE: lookup value from item record in invoice

    Posted 18 days ago
    One other thought here that's gotten me in the past. Since the Container Code field is an addon and not standard NAV, I have no idea what type of field it is, but if it's a Flowfield type (look at the Item table, and look at the Properties of that Container Code field), then you will have to add another little piece of code so it looks something like this:

    IF recItem.FINDFIRST THEN BEGIN
      recItem.CALCFIELDS("Container Code");

      gContainerCode := recItem."Container Code";

    END ELSE

      gContainerCode := '';

    Just one more thing to check...
    Good Luck!

    ------------------------------
    Jim Brewer
    Silverware
    beaverton AZ
    ------------------------------

    Conference-BCNAVUG_200x200


  • 10.  RE: lookup value from item record in invoice

    TOP CONTRIBUTOR
    Posted 17 days ago
    Thanks Jim

    Started working inexplicably next morning

    Thanks for tip on FlowFields

    ------------------------------
    Mark Anderson
    Director of ERP Systems
    Clesen Wholesale
    Evanston, IL
    ------------------------------

    Conference-BCNAVUG_200x200


  • 11.  RE: lookup value from item record in invoice

    Posted 18 days ago
    The "Container No." field on the Item record isn't a FlowField is it?  If so, you'd have to do a calcfield on it.

    ------------------------------
    Christopher Boyle
    iCepts Technology Group, Inc.
    Middletown PA
    ------------------------------

    Conference-BCNAVUG_200x200


If you've found this thread useful, dive deeper into User Group community content by role