How to refer to a field in a subform??

VotucVotuc Member Posts: 206
So, how do I refer to a field in a subform?? :-k

This is on the Sales Order Form

I need something like the following:

IF SalesOrderSubform."Vendor No." = 'Labor"
Then.... rec."Tax Code" = 'VA-COST-TAXABLE'; (change value of Tax Code field in Sales Header).




Thanks

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    You have Filter Sales Lines as
    SalesLine.SETRANGE("Document Type","Document Type");
    SalesLine.SETRANGE("Document No.","No.");
    IF SalesLine.FINDSET THEN
      REPEAT
        IF SalesLine."Vendor No." = 'Labor" THEN
          "Tax Code" = 'VA-COST-TAXABLE';
      UNTIL SalesLine.Next = 0;
    
  • matttraxmatttrax Member Posts: 2,309
    You can write a function in the subform to return the value you need.
  • kinekine Member Posts: 12,562
    Please, never use the "magic constants" in your code. Add the 'Labor' and 'VA-COST-TAXABLE' into some setup table and use the values in the code. Magic constants are quickly-done-big-problems-in-future
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • TheDoubleHTheDoubleH Member Posts: 67
    kine wrote:
    Please, never use the "magic constants" in your code. Add the 'Labor' and 'VA-COST-TAXABLE' into some setup table and use the values in the code. Magic constants are quickly-done-big-problems-in-future

    phew - I wasn't the only one having a heart attack =D>
    Kind Regards

    Henrik Helgesen,
    President | Helgesen Consulting
    about.me | LinkedIN
  • VotucVotuc Member Posts: 206
    kine wrote:
    Please, never use the "magic constants" in your code. Add the 'Labor' and 'VA-COST-TAXABLE' into some setup table and use the values in the code. Magic constants are quickly-done-big-problems-in-future

    You are referring to "rec"? Yes that is a good point. :mrgreen:
  • SavatageSavatage Member Posts: 7,142
    So instead of hardcoding a "Vendor No." = Labor.

    You're better off adding a field to the vendor table that you can check off(boolean) like Labor Vendor.

    Then by having Salesline."Vendor No." you're able to get the rest of the vendor info. Makes if more flexible and easier to add additional vendors if needed in the future or change them.

    if vendor.get(Salesline."Vendor No.") then begin
    if vendor."Labor vendor" then
    ...
    ...
    ..
    end;

    same thing with the tax code - you can add a default labor tax setup field (or whatever your working on) in salessetup. that you can pull into your code salessetup.get; that allows you the same flexability.

    So many times over the years I've heard in our office alone "we need this change, it's just for this customer or/vendor or/Item. No other will be like this..ever!" then in a month Oh there's another one we need to treat like ABC. I say good - now go check the box I made the first time :)"
  • VotucVotuc Member Posts: 206
    Savatage wrote:
    So instead of hardcoding a "Vendor No." = Labor.

    You're better off adding a field to the vendor table that you can check off(boolean) like Labor Vendor.

    Then by having Salesline."Vendor No." you're able to get the rest of the vendor info. Makes if more flexible and easier to add additional vendors if needed in the future or change them.

    I'm not certain I understand....

    I will tell you what the request is:

    If the word Labor is detected in the Sales Lines area of the sales order Form/Page, we need to change the Tax code to something like VA-INSTALL. These tax codes will be copies of the normal tax codes. For all orders that have INSTALL in the Tax code, we will show zero Sales Taxes on the Customer Invoice. Then we calculate tax based on the COST instead of the retail price.

    This is only for projects where they hire a subcontractorto install their product (do the labor).
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • SogSog Member Posts: 1,023
    Even then it ought to be done by setup instead of hardcoding.
    What if the tax VA-INSTALL has to be changed? (or renamed, or ...)
    Those "constants" should immediatly be recognized as parameters.
    So instead of checking if the vendor no. is a specific vendor (labor: subcontractor), you ought to get the vendor and check if the subcontractor/laborer boolean is true.
    If you don't want to depend on the vendor no. you could check for each salesline if the description contains labor.
    something like:
    if strpos(salesline.description,salesetup.magicword (which contains "labor")) > 0 then
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
Sign In or Register to comment.