Advanced MODIFY

oioi007oioi007 Member Posts: 41
hello

I want to make a Button that will change all <Shipping Agent Codes> by <Salesperson Code> in <Customer> Table.
On a Salespeople form I've added a TEXTBOX with "Shipping Agent Codes" SourceEXpr.

for example, When I'll change <Shipping Agent Code> (DHL) to <Salesperson Code> (AH) there will be added a Button "Change", that'll change all (AH) Salespersons with (DHL) Shipping Agent Codes in Customer Table.

I've wrote the following code on
OnPush Trigger


ShippingAgent.SETRANGE(Code);
Salesperson.SETRANGE(Code);
Customer.SETRANGE("Shipping Agent Code");
IF ShippingAgent.FINDFIRST THEN
REPEAT
Salesperson.SETRANGE(Code);
ShippingAgent.SETRANGE(Code);
IF Salesperson.FINDFIRST() THEN
REPEAT
Customer.SETFILTER(Customer."Salesperson Code", Salesperson.Code);
Customer.SETFILTER(Customer."Shipping Agent Code", ShippingAgent.Code);
IF Customer.FINDFIRST() THEN
REPEAT
Customer."Shipping Agent Code" :=ShippingAgent.Code;
Customer.MODIFY;
UNTIL Customer.NEXT = 0;
UNTIL Salesperson.NEXT= 0;
UNTIL ShippingAgent.NEXT =0;

what's wrong with this code,
please someone help me
I'll appriciate it :)

Answers

  • krzychub83krzychub83 Member Posts: 120
    hm...

    This code is changing all "Shipping Agent Code" from Customer table with
    "Shipping Agent Codes" from Salespeople table. Put this code to the button's OnPush trigger.

    One local variable Customer - Record Table 5200
    CLEAR(Customer);
    Customer.SETFILTER("Salesperson Code", Rec.Code);
    IF customer.FINDSET THEN
      Customer.MODIFYALL("Shipping Agent Code",Rec."Shipping Agent Codes");
    

    I hope that this will help You...
  • BeliasBelias Member Posts: 2,998
    if you do a repeat...until routine, don't use findfirst!!!instead use findset!!
    see the help online! :mrgreen:
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
  • krzychub83krzychub83 Member Posts: 120
    Previous code was changing "Shipping Agent Codes" for current selected SalesPeople.
    This code is making it for all SalesPeople:
    CLEAR(salepeople);
    IF salepeople.FIND('-') THEN
    REPEAT
      CLEAR(customer);
      customer.SETFILTER("Salesperson Code", salepeople.Code);
      IF customer.FIND('-') THEN
        customer.MODIFYALL("Shipping Agent Code",salepeople."Shipping Agent Codes");
    UNTIL salepeople.NEXT = 0;
    
  • kinekine Member Posts: 12,562
    krzychub83 wrote:
    customer.SETFILTER("Salesperson Code", salepeople.Code);
      IF customer.FIND('-') THEN
        customer.MODIFYALL("Shipping Agent Code",salepeople."Shipping Agent Codes"); 
    

    Why you are using FIND('-') if you just want to know if the table IsEmpty? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    hope i understand:

    on salesperson you have the field "Shipping Agent Code". Now, if you change the value in this field on a Salesperson, in all customers, with the same salesperson code, should the "Shipping Agent Code" modified to the new value from sales person card. :?:

    1. Your new field has a table realtion to the table "Shipping Agent"
    2. now the source behind you button or behind the OnAfterValidate() Trigger of the field "Shipping Agent Code" in table sales person (13)
    if not confirm('Your question?',no) then
      exit;
    
    Customer.reset;
    Customer.setrange("Sales Person Code",Rec.Code);
    Customer.setrange("Shipping Agent Code",xRec."Shipping Agent code");
    Customer.modifyall("Shipping Agent Code",Rec."Shipping Agent code");
    

    Thats all.

    Regards
    Do you make it right, it works too!
  • krzychub83krzychub83 Member Posts: 120
    kine wrote:
    Why you are using FIND('-') if you just want to know if the table IsEmpty? ;-)

    It's a very bad habit... Thx Kine
  • oioi007oioi007 Member Posts: 41
    Great, it works now!

    Thank you very much 8)
Sign In or Register to comment.