Change color in form 516 "Sales Line"

cosch1cosch1 Member Posts: 37
Hi,
thanks al ot to everyone who answered. I found my mistake and solved the problem with your help!
=D> :D =D>

With best greetings from germany!!

csoch


Hi together,

i've got the problem, that the color don't want to change.... :cry:

In form 516 "Sales Line" i wrote this code in section "Sell-to customer No." - OnFormat(VAR TEXT : TEXT[1024]:):

SalesLine.RESET;
SalesLine.SETRANGE("Document Type",SalesLine."Document Type"::Order);
SalesLine.SETRANGE("Document No.","No.");
SalesLine.SETRANGE("Type",SalesLine."Type"::Item);
SalesLine.SETFILTER("Sell-to Customer No.",'190010|190020|190030|190040|190049|190072|190079|190080');
IF SalesLine.FIND('-') THEN
CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);


My problem: It doesn't work..... :oops:

Thanks for help!!

Greetings from germany
cosch

Answers

  • garakgarak Member Posts: 3,263
    //Variant 1
    if ("Sell-to Customer No." in ['190010','190030','190020']) then
      CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    
    //Variant 2
    MyCustomersToFilter := '''00032625'',''00032499'',''00000052'',''00011707'''; //or from a field in a setup table MyCustomersToFilter := MySetupTable.MyCustomersToFilterField
    
    if (STRPOS(MyCustomersToFilter,"Sell-to Customer No.") <> 0) then
      CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    
    //Variant 3
    if MyCustToFilter.get("Sell-to Customer No.") then
      CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    

    So, better is a Setup table where you store the Customer No.. so you are flexible and you must not ever change the sourcecode if a new customer must be red.

    Why do you need it red? Arre these blocked customers?

    Regards
    Do you make it right, it works too!
  • SavatageSavatage Member Posts: 7,142
    edited 2009-03-26
    If the code is on the sales line - what's the "find" doing?

    as above, instead of hard coding those customer numbers it's better to create a boolean field on the customer card called
    "Salesline Alert" or whatever name or reason you need "Sell-to Customer No." red.

    Customer->Record->Customer
    OnFormat(VAR Text : Text[1024];)
    Customer.GET("Sell-to Customer No.");
    IF Customer."Salesline Alert" THEN BEGIN
    IF ("Document Type" = "Document Type"::Order)
      AND (Type = Type::Item)
       THEN CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    END;
    

    Edit: "Salesline Alert" is a new field type boolean
  • Alex_ChowAlex_Chow Member Posts: 5,063
    "Sell-to customer No." - OnFormat(VAR TEXT : TEXT[1024]:)
    IF "Sell-to Customer No." in ['190010','190020','190030','190040','190049','190072','190079','190080'] then
      CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    

    Since you're at the form already, there's no need to get it.
  • SavatageSavatage Member Posts: 7,142
    Do you mean "Find it" in his code? - in my code you're getting the customer table beacuse a new boolean was created to make the reason for this code more flexible. and form 516 doesn't (on mine) have a customer table link
  • Alex_ChowAlex_Chow Member Posts: 5,063
    Sorry, I was responding to the original poster's code.

    In the code I put up, I'm not getting the customer record at all. I'm just looking at the characters that is on the Sell-to Customer No. field.
  • SavatageSavatage Member Posts: 7,142
    no need to be sorry - i was wondering what the find was trying to do too.

    A code like that is used more to run thru the lines and make some kind of change.
    there is actually no changing going on.
  • kinekine Member Posts: 12,562
    edited 2009-03-27
    I will make small research of your code:
    SalesLine.RESET;
    SalesLine.SETRANGE("Document Type",SalesLine."Document Type"::Order);
    SalesLine.SETRANGE("Document No.","No.");
    
    - ok, we are getting lines for this document, for same document we are on....
    SalesLine.SETRANGE("Type",SalesLine."Type"::Item);
    
    - ok, all Item lines of the current document
    SalesLine.SETFILTER("Sell-to Customer No.",'190010|190020|190030|190040|190049|190072|190079|190080');
    IF SalesLine.FIND('-') THEN
    CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    

    - and if there is some Item line for the current document, which customer is in the filter, make the line red.

    Result is> that you have field "Sell - to Customer No." colored into Red for all orders, which are for predefined set of customers, and have one or more Item lines. Of course, it is coloring other lines too, because you never set the color to black for other lines... ;-)

    Question is, if you can do the Customer condition better. And yes, you can (or better - it will be VERY GOOD to make it in another way). E.g. in this way:
    CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(0);
    
    SalesHeader.GET(SalesLine."Document Type","Document No."); //header for the line must exist
    Customer.GET(SalesHeader."Sell-to No."); //we assume that the customer is filled in before we are creating the lines
    
    if Customer."Color the order lines" then begin //is this order for customer for which we are coloring?
      SalesLine.RESET;
      SalesLine.SETRANGE("Document Type","Document Type"); //universal filtering - same code will work for Quotes, Cr. Memo etc.
      SalesLine.SETRANGE("Document No.","Document No.");
      SalesLine.SETRANGE("Type",SalesLine."Type"::Item);
      IF not SalesLine.ISEMPTY THEN  //it means- exist some Item line on this document???
        CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    end;
    

    PRO of this solution:
    - You can easilly add or remove customers for which the document will be colored just by changing value of the field (One check box on the customer card).
    - You are checking the existence of the Item line only for customers, for which it is relevant, thus creating no performance issue for other customers
    - You are not even reading the lines, you are just checking, if there is any or no. On SQL it means lower performance too
    - All other lines are black
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • rdebathrdebath Member Posts: 383
    cosch1 wrote:
    SalesLine.SETRANGE("Document No.","No.");
    Simple, and very common bug.

    Your Rec variable is a sales line.

    SalesLine."Document No." is a Document Number
    Rec."No." is an Item Number (or similar)

    Never gonna work.
  • dayakardayakar Member Posts: 68
    =D>
  • kinekine Member Posts: 12,562
    rdebath wrote:
    cosch1 wrote:
    SalesLine.SETRANGE("Document No.","No.");
    Simple, and very common bug.

    Your Rec variable is a sales line.

    SalesLine."Document No." is a Document Number
    Rec."No." is an Item Number (or similar)

    Never gonna work.

    Yes, I used the SalesHeader first, forgot to change it after I removed it... code was done from scratch without NAV... 8)

    Thanks for correction... original post updated...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    Why a filter on a separate variable of Record SalesLine? The Form 516 is based on table 37. so you can directly check in the OnFormat if the line must red or not. Why a searate SalesHeaderVar and SalesLineVar???

    You need only to check the condition (is a field set on the customer or is the customer in a setup table or what else) ....
    Do you make it right, it works too!
  • kinekine Member Posts: 12,562
    It depends on which lines must be colored. In this example, all lines (e.g. type=G/L Account, Resource etc.) for order having at least one Item line are colored. In your case, only the Item line itself will be colored or all regardless there is one Item line... but we do not know exact description of the functionality. All this was derived from the initial code...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • rdebathrdebath Member Posts: 383
    kine wrote:
    Thanks for correction... original post updated...
    Okay, ... Erm no it isn't ... erm ..
    _________________
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG

    Oh, I see, Well I did say it was a rather common bug :D:lol:
  • SavatageSavatage Member Posts: 7,142
    Savatage wrote:
    If the code is on the sales line - what's the "find" doing?

    as above, instead of hard coding those customer numbers it's better to create a boolean field on the customer card called
    "Salesline Alert" or whatever name or reason you need "Sell-to Customer No." red.

    Customer->Record->Customer
    OnFormat(VAR Text : Text[1024];)
    Customer.GET("Sell-to Customer No.");
    IF Customer."Salesline Alert" THEN BEGIN
    IF ("Document Type" = "Document Type"::Order)
      AND (Type = Type::Item)
       THEN CurrForm."Sell-to Customer No.".UPDATEFORECOLOR(255);
    END;
    

    Tested & works

    Edit: "Salesline Alert" is a new field type boolean
  • kinekine Member Posts: 12,562
    Still Harry, your example is doing something else than the original post... question is, if the original post was wrong in logic or not. :-D

    The original code (if it will be corrected to work) will do this:

    Order 1 Item CUST0001
    Order 1 G/L Account CUST0001
    Order 1 Resource CUST0001
    (all colored red because there is one line of type Item)

    Order 2 Resource CUST0001
    Order 2 G/L Account CUST0001
    Order 2 Resource CUST0001
    (no item line, no coloring)

    Your example will do:

    Order 1 Item CUST0001
    Order 1 G/L Account CUST0001
    Order 1 Resource CUST0001

    But what is correct must say cosch1, nobody else... 8)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • kinekine Member Posts: 12,562
    rdebath wrote:
    kine wrote:
    Thanks for correction... original post updated...
    Okay, ... Erm no it isn't ... erm ..
    _________________
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG

    Oh, I see, Well I did say it was a rather common bug :D:lol:

    1) Sorry, I edited my post and corrected the mistake, if you still saw the original post, it is your cache which is wrong...
    2) I didn't catch the second point... may be just my language barrier and limitation of written text... :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SavatageSavatage Member Posts: 7,142
    I went right to "making the sell-to customer red if it equals a certain customer no"

    with adding flexibility & no hard coding. I didn;t try to fix that code.
    :mrgreen:
  • rdebathrdebath Member Posts: 383
    kine wrote:
    rdebath wrote:
    kine wrote:
    Thanks for correction... original post updated...
    Okay, ... Erm no it isn't ... erm ..
    _________________
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG

    Oh, I see, Well I did say it was a rather common bug :D:lol:

    1) Sorry, I edited my post and corrected the mistake, if you still saw the original post, it is your cache which is wrong...
    2) I didn't catch the second point... may be just my language barrier and limitation of written text... :-k

    My original comment was to the message at the top of this topic by cosch1 and that was actually the line I quoted, he had exactly the same bug as you did.
Sign In or Register to comment.