Code-correct or not-Help needed

Hi…Can you please check and tell whether this code will work or not

Purpose :If the item on SL matches with the item on ILE,and if the Branch code in ILE is not empty then i have to check the Branch code on SL and if it is empty then the system has to throw a message to fill that field.

ILE = Item ledger entry
SL = Sales line

Code:
ILE.SETRANGE(ILE."Item No.",SL."No.");
IF ILE.FINDFIRST THEN
IF ILE."Branch code" <> ' ' THEN
SL.TESTFIELD(SL."Branch Code");

The last line is not working for me.So can anyone suggest me any other alternative or corrections in the same are appreciated…

It looks like the code should work but the logic is not good,

Does the Item only belong to one Branch, if it does then the value should be on the Item record and filled when the Item is selected.

If the Item can belong to many branches then you need more filters, open, location code, quantity etc: and these need to be filtered on posting, as you have not set a key on the ILE as the table gets lots of entries then this will slow down the filtering.

David

There will be only one entry,i can assure that.But my concern is the last line.As i am setting filters for ILE and checking the findfirst in ILE table and the last line belongs to Sales Line.That is where it is not working.

Any suggestions on that?

Ok I remember from another topic that you make unique custom items, so the code should be called from the Sales Line, as you are using the IF statement, the ILE is not being returned.

Looking at your code sample for the empty string you have a space ’ ’ this should be ‘’

ILE.RESET;
ILE.SETCURRENTKEY("Item No.");
ILE.SETRANGE("Item No.","No.");
IF ILE.FINDFIRST THEN BEGIN
IF ILE."Branch code" <> '' THEN
TESTFIELD("Branch Code");
END ELSE
MESSAGE('There is no Item Ledger Entry');

If the Branch Code should be the same then:

ILE.RESET;
ILE.SETCURRENTKEY("Item No.");
ILE.SETRANGE("Item No.","No.");
IF ILE.FINDFIRST THEN BEGIN
IF ILE."Branch code" <> '' THEN
TESTFIELD("Branch Code",ILE."Branch Code");
END ELSE
MESSAGE('There is no Item Ledger Entry');

David

Thank you…

I have written the code given by you on Item no field-on validate

The code is working fine,but when the below line

**TESTFIELD("Branch Code",ILE."Branch Code");**

is getting executed,the system is throwing a message to enter the value.But after clicking on the OK button of the message,i am not able to enter the value in the required field.

Any solution?

That is because you have the code before the “Brance Code” has a value.

If the Brance Code should be filled in by the User before they select the “Item No.” then:

TESTFIELD(“Branch Code”);
ILE.RESET;
ILE.SETCURRENTKEY(“Item No.”);
ILE.SETRANGE(“Item No.”,“No.”);
IF ILE.FINDFIRST THEN BEGIN
IF ILE.“Branch code” <> ‘’ THEN
TESTFIELD(“Branch Code”,ILE.“Branch Code”);
END ELSE
MESSAGE(‘There is no Item Ledger Entry’);

However if you want the Branch Code filled from the ILE then:

ILE.RESET;
ILE.SETCURRENTKEY(“Item No.”);
ILE.SETRANGE(“Item No.”,“No.”);
IF ILE.FINDFIRST THEN BEGIN
IF ILE.“Branch code” <> ‘’ THEN
“Branch Code” := ILE.“Branch Code”;
END ELSE
MESSAGE(‘There is no Item Ledger Entry’);

David

David,

That’s not the problem.Actually it is not Branch code,its customized field called SPC code and the problem is once the system is running the TESTFIELD code it is throwing a message requesting to fill the SPC code field.Then i am clicking on the OK button of the message.Now it has to allow me to fill the SPC code field,but it is not allowing me to move to the next field and also forcing me to remove the item code i have selected .

Solution please…

aravind:

TESTFIELD errors out, it will not allow you to do to continue processing the code or validating the field. Maybe having it prompt a MESSAGE for the user and re-checking they are filled out on Release of the sales order is better.

MESSAGE(‘Please fill out the SPC Code’); instead of TESTFIELD.

Kevin

Message is fine,but there are chances of ignoring the message.The requirement is to block the user if the field is not filled.

While releasing the order ,again we are just popping a message…IS there any other way out?

Aravind, definitely; but let them enter the Item and show them a message so they can try to fill it in.

On release, do the check again and use TESTFIELD or ERROR

The solution is first for you to learn Navision and how it works. Once you have done that to then train your users how to use it properly. Once you have done that you will understand the correct way to implement this requirement.

The way NOT to do this is to demand a solution from the forum.