Unable to post sales order if the dimension in header different with line

I need help,

Few hours ago i created a global dimension code in my nav. Is there anything i can do so that sales order / credit memo can’t be posted if the following condition applied :

Global dimension code in sales order header and sales order line are different.

for example :

Global dimension code in sales order header is A and in sales order line there is four line (three line have global dimension code A and one line have a global dimension code B).

If the condition above met then nav can’t post this sales order. But, if every sales line above have global dimension code A then nav will post it.

You need to write a code in Codeunit 80

You can write following

recSaleline.RESET;

recSaleline.SETRANGE(recSaleline.“Document Type”,“Document Type”);

recSaleline.SETRANGE(recSaleline.“Document No.”,“No.”);

recSaleline.SETRANGE(recSaleline.Type,recSaleline.Type::Item);

IF recSaleline.FINDFIRST THEN

BEGIN

REPEAT

IF (“Shortcut Dimension 1 Code”<>recPSaleline.“Shortcut Dimension 1 Code”) THEN

ERROR(‘Dimension not matching…’);

UNTIL recSaleline.NEXT=0

END;

Thanks, but it seems not working.

what is the table defined in recSaleline & recPSaleline ?

I guess recSaleline is record variable of Sales Line table

and recPSaleline is typo

it should be recSaleline only

I dont really understand amol’s code. Perhaps i need to learn basic coding asap.

In the meantime, could you please tell me how the logic work in that code ?

i want to know how that works.

Hi,

What you have not understand in this code ?

In above code system will check header dimension and line dimension are matching or not if not the system will throws an error.