SBX - Search With Button

SBX - Forum Post Title

Update Unit Price on Sales Line when changing Sales Type in Sales header

Microsoft Dynamics NAV Forum

Mosaheb Ellahebox asked a question on 18 Mar 2015 7:39 AM
My Badges

Question Status

Verified

In Sales Header, we have included a new field Sales Type(Datatype: Option, Values: Normal, Tender, Special Order).  On the item card besides the current Unit Price field (i.e., Normal) we have added two new unit price fields for Tender and Special Order.

THE ITEM CARD

THE SALES INVOICE

How can we update the unit price on the Sales Line when changing the Sales Type:

1) when adding a new item on the sales line, and

2) for existing lines when changing the sales type.

I've verified through the code unit 7000 Sales Price Calc Mgt which includes the function CalcBestUnitPrice.

The following changes were done (code between ME01-START & END) but the correct price is not being displayed:

Does anyone has any idea how same can be done.

Nav version: 2013R2

Thanks & regards

Reply
Suresh Kulla responded on 18 Mar 2015 8:45 AM
My Badges
Verified Answer

I did not notice the Get Statement for the SalesHeader, i think you should use get SalesHeader first using

SalesHeader.GET("Document Type","Document No."). 

The other thing is there is a function called UpdateSalesLines on Sales Header table you should use the same kind of logic on the Sales Type field to update the sales lines.

Call that function on the validate of the sales type field and add code on the updatesaleslines function for the FIELDCAPTION("Sales Type"):

SalesLine.UPdateUnitPrice;

Reply
Mahesh responded on 18 Mar 2015 11:06 AM
My Badges
Verified Answer

Yes, as mentioned by Suresh, you need to check whether the Sales Header has the record by calling the SalesHeader.GET(......).

Best Regards,

MMV

Reply
Mosaheb Ellahebox responded on 24 Mar 2015 7:41 AM
My Badges

Dear Suresh,

Thanks for responding to my query.

However, when the FIELDCAPTION was used, the unit price is not being updated when changing the 'Sales Type' on the Sales Header.  Please find below the code and the debug screen:

Do you have any idea how to correct same

Thanks & regards

mosaheb

Reply
Suresh Kulla responded on 24 Mar 2015 9:11 AM
My Badges
Suggested Answer

It looks like your code is executed, does it not hit your IF statement where you added the unit price code?

One other thing you don't need SalesLine.SETRANGE(".....) statement

Reply
Mahesh responded on 24 Mar 2015 9:56 AM
My Badges
Verified Answer

Hi,

If you look at the above code, the Debugger shows that the Item table is not initialized.  How you got the Item record by using IF Item.GET(SalesLine."No.") THEN;  ?

Best Regards,

MMV

Reply
Mosaheb Ellahebox responded on 25 Mar 2015 2:45 AM
My Badges

Thanks MMV, in fact I was missing the condition IF Item.GET(SalesLine."No.") THEN

Regards

Reply
Mahesh responded on 25 Mar 2015 2:46 AM
My Badges

You are welcome!!!

Reply
manideep22 responded on 14 Jun 2019 3:33 PM

I was trying to copy Document date field of Sales header to a newly created field Job activity field of Sales Line. I'm writing following code in UpdateSalesLines and it is throwing "the return value should be used for this function" at FIELDCAPTION method. Below is my code

 ELSE

     ConfirmResvDateConflict;

FIELDCAPTION("Document Date") : SalesLine."Job Activity Date";

END;

I'm calling the method in Validate as

Document Date - OnValidate()

UpdateSalesLines(FIELDCAPTION("Document Date"),FALSE);

Reply
Suresh Kulla responded on 18 Mar 2015 8:45 AM
My Badges
Verified Answer

I did not notice the Get Statement for the SalesHeader, i think you should use get SalesHeader first using

SalesHeader.GET("Document Type","Document No."). 

The other thing is there is a function called UpdateSalesLines on Sales Header table you should use the same kind of logic on the Sales Type field to update the sales lines.

Call that function on the validate of the sales type field and add code on the updatesaleslines function for the FIELDCAPTION("Sales Type"):

SalesLine.UPdateUnitPrice;

Reply
Mahesh responded on 18 Mar 2015 11:06 AM
My Badges
Verified Answer

Yes, as mentioned by Suresh, you need to check whether the Sales Header has the record by calling the SalesHeader.GET(......).

Best Regards,

MMV

Reply
Mahesh responded on 24 Mar 2015 9:56 AM
My Badges
Verified Answer

Hi,

If you look at the above code, the Debugger shows that the Item table is not initialized.  How you got the Item record by using IF Item.GET(SalesLine."No.") THEN;  ?

Best Regards,

MMV

Reply
Suresh Kulla responded on 24 Mar 2015 9:11 AM
My Badges
Suggested Answer

It looks like your code is executed, does it not hit your IF statement where you added the unit price code?

One other thing you don't need SalesLine.SETRANGE(".....) statement

Reply

SBX - Two Col Forum

SBX - Migrated JS