How to change sale line from another !

haihthhaihth Member Posts: 32
Hi all member,

I have a problem when customize the Sale Order.

so0901202.jpg

Look at picture, When I on third line.

After I input No Item, I wanna change Unit Price of first and second sale lines.
I write following code in trigger OnValidate of No. field:
//for first line
tmpSalesLine.SETRANGE(tmpSalesLine."Document Type","Document Type");
tmpSalesLine.SETRANGE(tmpSalesLine."Document No.","Document No.");
tmpSalesLine.SETRANGE(tmpSalesLine."Line No.",10000);
IF tmpSalesLine.FindFirst() THEN
BEGIN
tmpSalesLine."Unit Price":=1000;
tmpSalesLine.MODIFY;
END;
//more for second line

The value of Unit Price on the first line is not change until i click on it. I try some code below :
tmpSalesLine.VALIDATE("Unit Price"); --- everything is not change
CurrForm.UPDATE(); --- error, you can't use form update here
Rec.VALIDATE("Unit Price"); ---everything is not change

I don't know how to refresh this subform to update new value for first and second line

Can anybody help me?

Thanks very much.

Comments

  • kinekine Member Posts: 12,562
    1)
    tmpSalesLine."Unit Price":=1000;
    tmpSalesLine.MODIFY;
    
    No validation? No triggers? Is it correct?
    2)
    tmpSalesLine.SETRANGE(tmpSalesLine."Line No.",10000);
    
    Are you sure that the first line have no. 10000? What about deleting the line and creating new one at the end? I will never hardcode such a thing...
    3) From where is your code called? This is the critical point...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • haihthhaihth Member Posts: 32
    kine wrote:
    1)
    tmpSalesLine."Unit Price":=1000;
    tmpSalesLine.MODIFY;
    
    No validation? No triggers? Is it correct?
    2)
    tmpSalesLine.SETRANGE(tmpSalesLine."Line No.",10000);
    
    Are you sure that the first line have no. 10000? What about deleting the line and creating new one at the end? I will never hardcode such a thing...
    3) From where is your code called? This is the critical point...

    1,
    2: I sure the line no 10000. (It's just a example. Actually, I will browse all previous sale line and change all the unit price belong to current No Item. for discount purpose)
    3. I write that code in trigger of No. field ( OnValidate )

    I said that: The value Unit Price of the first line have changed right. So code is right . But it only change when i click on it ( on column Unit Price of first line ).
    So I think because of subform is not update the new value. ( I've tried tmpSalesLine.Validate("Unit Price"), but it isn't work)

    can anybody help me?
  • kinekine Member Posts: 12,562
    The problem is that the form updates all the lines only in some cases, thus you need to update it manually, but it cannot be done from table code, but from from code. It means you can try to add CurrForm. UPDATE into onAfterValidate of the field on the form.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.